0

我有一个使用两个 png 的动画精灵。动画效果很好。我有另一种在游戏结束时运行的方法。

 //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(@"让老鼠伤心");

[self stopAllActions];


[greyMousePomPom setTexture:[[CCTextureCache sharedTextureCache] addImage:@"gray_mice_pom_anime_03.png"]]; 

}

我知道这种方法有效,因为它是 NSLogging 并且纹理正在发生变化。但是为什么动画没有停止?我试图通过标签和声明动作来删除它,但没有成功。

我知道有很多人比我聪明..你能帮忙吗?

4

1 回答 1

2

您现在正在做的是停止添加到当前节点的所有动画:

self

如果您向 self 添加任何操作,则此命令可以完全停止所有操作。

相反,您需要做的是,您需要在stopAllActions添加操作的对象上调用该方法:

[greyMousePomPom stopAllActions];

高温高压

于 2011-09-12T23:25:16.693 回答