代码 ::
if (CGRectIntersectsRect(food.sprite.boundingBox, playerRect)) {
[food.sprite stopAllActions];
[walkAnimFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"newpackman2.png", 0]]];
[walkAnimFrames addObject: [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"newpackman3.png", 1]]];
walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.2f];
self.walkAction = [CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
self.walkAction.tag = 1;
[chef runAction:_walkAction];
}
它工作正常,当对象与厨师相撞但连续运行时它会启动动画。
我想在 3-4 秒后停止动画。
我用过[sprite stopActionByTag:1]
,但它对我不起作用,一旦启动它就不会暂停。