在精灵本身完成动画后,我试图从我的主游戏层中删除一个精灵......为了实现这一点,我首先尝试将一个块传递给精灵对象的 CCSequence,如下所示:
#Game.m
// some method
[self.spriteMan zoomAwayWithBlock:{[self destroySpriteMan];}];
[self createNewSpriteMan];
}
-(void)destroySpriteMan {
[self removeChild:self.spriteMan cleanup:YES];
}
#SpriteMan.m
-(void)zoomAwayWithBlock:(void(^)())block {
[self runAction:[CCSequence actions: [CCScaleTo actionWithDuration:2.0f scale:1.0f],
[CCCallFuncN actionWithBlock:block],
nil]];
}
我想知道 self.spriteMan 的绑定是否在动画完成之前被调用 [self createNewSpriteMan] 搞砸了……所以我在调用它之前将 spriteMan 存储在 tempSpriteMan 变量中,并尝试在 tempSpriteMan 上删除Child .....两者都立即导致崩溃。
然后我重写了它以使用选择器和目标:
#game.m
[self.spriteMan zoomAwayWithSelector:@selector(destroySpriteMan:) target:self];
-(void)destroySpriteMan:(SpriteMan *)spriteMan {
[self removeChild:spriteMan cleanup:YES];
}
#SpriteMan.m
-(void)zoomAwayWithSelector:(SEL)sel target:(id)target {
[self runAction:[CCSequence actions: [CCScaleTo actionWithDuration:2.0f scale:1.0f],
[CCCallFuncN actionWithTarget:target selector:sel],
nil]];
}
同样的结果..每次都崩溃......我做错了什么?