2 Replies Latest reply on Mar 4, 2008 2:46 PM by McFazstp

    bezier curve for quad path

    Level 7
      hello everyone

      i have the following code which im using to move an image from one quad to
      another. Currently its moving in a straight line. I want the path to be more
      attractive. I hear i can manage it by integrating a bezier curve.

      I hope someone could show me how i could do that.

      Any help is appreciated.

      thanx

      ahmed



      Heres the code

      property sp

      property desQuad, myQuad

      property pnt1startx, pnt1endx, pnt1starty, pnt1endy

      property pnt2startx, pnt2endx, pnt2starty, pnt2endy

      property pnt3startx, pnt3endx, pnt3starty, pnt3endy

      property pnt4startx, pnt4endx, pnt4starty, pnt4endy

      property p



      on beginSprite me


      p =0

      sp = sprite(me.spriteNum)

      myQuad = sp.quad

      desQuad = sprite("destSprite").quad


      -- point1

      pnt1startx = myQuad[1][1]

      pnt1endx = desQuad[1][1]

      pnt1starty = myQuad[1][2]

      pnt1endy = desQuad[1][2]



      --point2

      pnt2startx = myQuad[2][1]

      pnt2endx = desQuad[2][1]

      pnt2starty = myQuad[2][2]

      pnt2endy = desQuad[2][2]


      --point3

      pnt3startx = myQuad[3][1]

      pnt3endx = desQuad[3][1]

      pnt3starty = myQuad[3][2]

      pnt3endy = desQuad[3][2]


      -- point4

      pnt4startx = myQuad[4][1]

      pnt4endx = desQuad[4][1]

      pnt4starty = myQuad[4][2]

      pnt4endy = desQuad[4][2]

      end





      on mouseup me


      repeat while sp.quad <> desQuad


      p = p + .01


      pnt1x = p * (pnt1endx - pnt1startx) + pnt1startx

      pnt1y = p * (pnt1endy - pnt1starty) + pnt1starty


      pnt2x = p * (pnt2endx - pnt2startx) + pnt2startx

      pnt2y = p * (pnt2endy - pnt2starty) + pnt2starty


      pnt3x = p * (pnt3endx - pnt3startx) + pnt3startx

      pnt3y = p * (pnt3endy - pnt3starty) + pnt3starty


      pnt4x = p * (pnt4endx - pnt4startx) + pnt4startx

      pnt4y = p * (pnt4endy - pnt4starty) + pnt4starty


      sp.quad = [Point(pnt1x,pnt1y), point(pnt2x,pnt2y), point(pnt3x,pnt3y),
      point(pnt4x,pnt4y)]

      if sp.quad = desQuad then exit repeat

      put sp.quad "sp"

      put desQuad "des"





      updatestage


      end repeat


      end