我有一个使用两个ping的动画精灵。动画效果很好。我有另一个方法在游戏结束时运行。
//Grey mouse with Pompom
greyMousePomPom = [CCSprite spriteWithFile:@"pink_mice_pom_anime_01.png"];
greyMousePomPom.tag=132;
[self addChild:greyMousePomPom z:6];
greyMousePomPom.position = CGPointMake(550, 70);
//Grey Pom Pom Mouse animation
CCAnimation *greyMousePomPomAnimate = [CCAnimation animation];
[greyMousePomPomAnimate addFrameWithFilename:@"gray_mice_pom_anime_01.png"];
[greyMousePomPomAnimate addFrameWithFilename:@"gray_mice_pom_anime_02.png"];
id greyMousePopPomAnimationAction = [CCAnimate actionWithDuration:1.3f animation:greyMousePomPomAnimate restoreOriginalFrame:NO];
repeatAnimationPomPom2 = [CCRepeatForever actionWithAction:greyMousePopPomAnimationAction];
[greyMousePomPom runAction:repeatAnimationPomPom2];
当我运行我的方法来改变动画精灵的纹理并停止它们时,动画在新纹理后面继续。
-(void) changePomPomMiceToSadFaceForFreeFall
{NSLog(@"making the mice sad");
[self stopAllActions];
[greyMousePomPom setTexture:[[CCTextureCache sharedTextureCache] addImage:@"gray_mice_pom_anime_03.png"]];
}
我知道这个方法是有效的,因为它是nsloging和纹理正在变化。但是为什么动画没有停止呢?我试过通过标签和声明动作来删除它,但是没有成功。
我知道有很多人比我聪明。你能帮忙吗?你现在正在做的是停止所有添加到当前节点的动画:
self
如果您在self中添加了任何操作,那么此命令将完全可以停止所有操作。
相反,您需要做的是,您需要调用您添加动作的对象的stopAllActions
方法:
[greyMousePomPom stopAllActions];
HTH