在我的代码小行星接近飞船时,如果激光击中小行星,我想实现爆炸动画。小行星应该运行爆炸动画并切换到隐形模式。
击中目标时没有动画,目标成功切换到隐形模式。在不将对象设置为不可见的情况下,动画运行良好。当我因为程序代码将它放在一起而没有看到动画时,它很快将对象设置为不可见。
我怎样才能看到动画然后将其设置为不可见模式。(目标又名小行星的速度各不相同,其中一些太快而另一些太慢)使目标隐形的想法是防止它们撞到船。
我试过这个问题&回答cocos2d autoremove sprite after animation didn't work
for (CCSprite *asteroid in _asteroids)
{
if (!asteroid.visible) continue;
for (CCSprite *shipLaser in _shipLasers)
{
if (!shipLaser.visible) continue;
if (CGRectIntersectsRect(shipLaser.boundingBox, asteroid.boundingBox))
{
[[SimpleAudioEngine sharedEngine] playEffect:@"explosion_large.caf"];
//explosion zombie animation starts
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 12; ++i)
{
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"zombieexplodes%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation
animationWithFrames:walkAnimFrames delay:0.1f];
_dieAction = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[asteroid runAction:_dieAction];
//explosion zombie ends
[self addPoint];
//change meme to woohoo.png
[_ship setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: @"woohoo.png"]];
shipLaser.visible = NO;
[asteroid setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: @"zombieexplodes13.png"]];
//asteroid.visible=NO;
continue;
}
}
}