13

I need to move a sprite from one CGPoint to another using Cocos2d for the Iphone. The problem is that the animation should be along a bezier.

Basically I would use this :

id move = [CCMoveTo actionWithDuration:.5f position:ccp(100,200)];
[sprite runAction:move];

Now how can I do this in a non linear path ?

Undo
  • 25,519
  • 37
  • 106
  • 129
eemceebee
  • 2,656
  • 9
  • 39
  • 49

2 Answers2

29

Try this

ccBezierConfig bezier;
bezier.controlPoint_1 = ccp(0, s.height/2);
bezier.controlPoint_2 = ccp(300, -s.height/2);
bezier.endPosition = ccp(300,100);

id bezierForward = [CCBezierBy actionWithDuration:3 bezier:bezier];
elementsense
  • 1,540
  • 3
  • 15
  • 21
  • How could I constrain my sprite to this bezier path so, of example, it could not be dragged anywhere except for along that path? – tallen11 Jul 31 '12 at 21:49
3

Well, actually I was once again too fast seeking for help.

Found the solution, there is a method : CCBezierTo

eemceebee
  • 2,656
  • 9
  • 39
  • 49