Desperate help with animatied sprites required please

Desperate help with animatied sprites required please
0.0 0


Hi Guys,

I’ve been having some trouble getting a sprite to animate, which is a huge problem as the game I’m making relies heavily on animated sprites. I’ve been working from this example ( but I’ve noticed that most of the methods are now deprecated so I’ve amended where necessary.

Here is my code for setting up the animation:-

@ CCArray *FrameArray = CCArray::create();
//Create an Animation Object
m_pGruntAnimation = CCAnimation::create;
//Set up new sprite to add animation to
CCSprite *spriteAnim = CCSprite::create~~>spriteFrameByName);
//create the animate action and set up parameters
CCAnimate animate = CCAnimate::create;
//Repeat animation forever
act = CCRepeatForever::create;
//Run the action
//Attach new sprite to parent
m_pObjectsSprite~~>addChild(spriteAnim, 5, 0);@

All this code does is add a child sprite to the parent but it does not animate ever.
Can anyone point out where I’m going wrong, what I’m missing out or offer an alternative?


I found the problem guys so I’ll post the solution in case anyone has a similar problem.

the line:-

m_pGruntAnimation = CCAnimation::create(FrameArray);

is wrong. It needs a second parameter to define the delay between each frame.

like so:-

m_pGruntAnimation =CCAnimation::create(FrameArray, (1.0f/FrameArray->count()));

where the 1.0f is the animation length and FrameArray->count() is obviously the number of frames (so a 10 frame animation will have a pause of 1.0f/10.0f or 0.1 seconds between frames)

I’m not sure if this is a bug or if its intended behavior but it is really annoying. I even tried setting the delay separately but that didn’t work either. Having the second parameter is the only thing that worked for me.

Hope this helps someone else.


Is this a copy&paste error? This should not even compile!