Moving an animated character

Moving an animated character
0.0 0


Hi, i am playing around with animations. I created a CCAnimation object with CCAnimation::animationWithFrames( …. ).

Now, what i want to do is to play the animation (i know how to do that) and at the same time move the sprites of the animation
horizontally (so, if the animation represents a walk, the character will seems to walk to the left (or right)).

I don’t know how to tell cocos to draw each frame of the animation with a different x-position. Maybe i should use MoveTo() action?


sprite->runAction( CCSpawn::actions(CCAnimation::actionWithDuration(time, animation, false),
                                                   CCMoveTo::actionWithDuration(time, ccp(x,y)),  // or CCMoveBy
                                                   NULL) );

CCSpawn is the key.


Ok, thx. But what if i want to repeat the animation of the character walking until it reach the moveto goal?
I tried CCRepeatForever but didn’t work:

//CCAnimate::actionWithDuration(.2f, animation, false),
CCRepeatForever::actionWithAction( CCAnimate::actionWithDuration(.2f, animation, false) ),
CCMoveTo::actionWithDuration(3.0f, ccp(s.width/2+50, s.height/2)
), // or CCMoveBy

The sprite is placed, initially, at the center of the screen.