Who know?
Like this.
I init a sprite with texture,then I put a animation in it.
Now I need change a new animation with it.
How to achieve it?
I try some codes,but failed.
//Stop the running animation
this~~>CurSprite~~>stopAllActions();
//the new animation
CCAnimation *curAnimation=Helper_Animation::GetAnimation(changeClass.Weight,changeClass.Height,changeClass.DelayTime,changeClass.IsLine,this~~>CurDirect,changeClass.FrameAtlasFilePath);
//init the sprite again
this~~>CurSprite=CCSprite::spriteWithTexture(CCTextureCache::sharedTextureCache()>addImage,CCRectMake);
//set the sprite new position
this>CurSprite~~>setPosition);
this~~>CurSprite~~>retain;
//put the new animation in sprite
this~~>CurSprite->runAction(CCAnimate::actionWithAnimation(curAnimation));
I don’t think you have to re-initialise the sprite, just initialising it initially should be fine.
And a note, if your calling retain(), remember to call release() before your program closes.
I am not sure about how your animation is set-up for the new animation as that is the only line I haven’t met before…so if it still doesn’t work, that is where your problem will be I think.
I don’t think you have to re-initialise the sprite, just initialising it initially should be fine.
>
And a note, if your calling retain(), remember to call release() before your program closes.
>
I am not sure about how your animation is set-up for the new animation as that is the only line I haven’t met before…so if it still doesn’t work, that is where your problem will be I think.
Thank you.
I had solved it.
Just need to initialise it again.
Like this:
this~~>CurSprite~~>initWithTexture(CCTextureCache::sharedTextureCache()>addImage,CCRectMake);
If use:
this>CurSprite=CCSprite::spriteWithTexture(CCTextureCache::sharedTextureCache()->addImage(changeClass.FrameAtlasFilePath),CCRectMake(0,0,changeClass.Weight,changeClass.Height));
It doesn’t work.