Rightnow I have a sprite running around on the screen across the X-axis (side scroller style). When the sprite reaches the endPosition point, I call [sprite stopAllActions]. When the actions stop, the sprite is displayed in whatever the last frame happened to be. Is there a way to make the whole animation complete so that the sprite is in the "resting" position and not in a "running" position?
Possible to always make sprite animation complete on last frame?
(3 posts) (2 voices)-
Posted 1 year ago #
-
Can't you just use a method like
-(void) setDisplayFrame: (NSString*) animationName index:(int) frameIndexto set the "resting" animation when the sprite stops?
But i assume you want the action to run until end when the sprite stops, is that it? In that case don't call stopAllActions but wait till the animation is done (i'm not sure if there are ways to find this out). Or stopAllActions and then restart the animation again but with the current frame of the animation as starting frame and without looping the animation. But i don't know if CCSprite supports any of this, as i haven't worked with animations much yet.
Posted 1 year ago # -
Thanks, that's the function I was trying to use. It kept crashing, but that's because I didn't realize you have to call addAnimation manually. Thanks for your help!
Is there any particular reason why, when you animate a sprite, the animation isn't automatically added to the animation dictionary in AtlasSprite? If I'm animating a sprite, I would intuitively think that the animation should be added automatically.
AtlasSpriteManager *mgr = [AtlasSpriteManager spriteManagerWithFile:@"spritesheet.png" capacity:100]; [self addChild:mgr z:0 tag:101]; AtlasSprite *sprite = [AtlasSprite spriteWithRect:CGRectMake(0, 205, 50, 44) spriteManager: mgr]; AtlasAnimation *animation = [AtlasAnimation animationWithName:@"run3" delay:0.06f]; for(int i=0;i<8;i++) { int x= i % 5; int y= 1; [animation addFrameWithRect: CGRectMake(x*50, y*205, 50, 44) ]; } [sprite addAnimation:animation]; [mgr addChild:sprite z:1 tag:102];Posted 1 year ago #
Reply
You must log in to post.