How do I set the initial frame of the sprite?

So, I have the CCSprite instance and I run animation, using runAction function. I want to stop animation at any moment. And I want to restore the first frame of the animation. How can I do this?
Thank you.

bump

At anytime you can set a frame using:
this -> setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("warant-walk1.png"));
I think you should stop the action first and then reset the frame.
Best of luck.

Jobed Rony wrote:

this -> setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("warant-walk1.png"));

But what if I have several files with the same name? For example, if they are in different directories? Moreover, I can change the name of a sprite.
Maybe should exists method like sprite->getAnimation()->setFrame(0), where 0 is the index of initial frame? I can’t find something like that…

Thank you.

I didn’t find any method for that too.
May be it can be retrieved from “m_pFrames” array by writing custom method.
Not sure but you can try.

Jobed Rony wrote:

May be it can be retrieved from “m_pFrames” array by writing custom method.
Already did it via getFrames():

CCSpriteFrame *initialFrame = (CCSpriteFrame *)m_animRun->getAnimation()->getFrames()->objectAtIndex(0);
m_sprite->setDisplayFrame(initialFrame);

But when I trying to setDisplayFrame with retrieved frame I get segfault. Oddly.

Typecasting is bad.

I should do this:
CCAnimationFrame *initialFrame = (CCAnimationFrame *)m_animRun->getAnimation()->getFrames()->objectAtIndex(0);
m_sprite->setDisplayFrame(initialFrame->getSpriteFrame());

Because m_pFrames contains objects of CCAnimationFrame class, not of CCSpriteFrame.

Done.