在我的代码中,朝向船的小行星 如果激光撞击小行星,我想实现爆炸动画。 小行星应运行爆炸动画并切换到隐形模式。Cocos2D setvisible =动画完成后没有
当目标被击中时,没有动画,目标成功切换到隐形模式。没有将对象设置为不可见,动画效果很好。当我将程序代码放在一起而没有看到动画时,它很快将对象设置为隐形。
我怎样才能看到动画,然后将其设置为隐形模式。 (目标aka小行星速度不同,其中一些速度太快,而其他速度太慢) 将目标置于不可见状态的想法阻止了它们撞上船。
我想这个问题的答案& cocos2d autoremove sprite after animation没有工作
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;
}
}
}
我喜欢CCCallBlockN样品: CCCallBlockN * calFuncN = [CCCallBlockN actionWithBlock:^(CCNode *节点){ node.visible = FALSE; } – zeiteisen 2012-07-26 19:06:05
@zeiteisen,感谢这个信息,它减少了代码行数。 – Guru 2012-07-26 19:17:18
像Matthijs Hollemans说的那样:懒惰是程序员的最大美德:) – zeiteisen 2012-07-26 19:44:30