スプライト自体のアニメーション化が完了した後、メインゲームレイヤーからスプライトを削除しようとしています...これを実現するために、最初に次のようにブロックをスプライトオブジェクトの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でremoveChildを試行しました。 .....どちらもすぐにクラッシュします。
次に、セレクターとターゲットを使用するようにこれを書き直しました。
#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]];
}
同じ結果..毎回クラッシュ......何が間違っているのですか?