新しいアクションを実行するときに、以前はstopAllActionsを使用していました。色が徐々に追加され、「リバース」への呼び出し (CCTintBy の(CCActionInterval*) リバース関数を参照) が呼び出されなかった (停止したため)ため、 CCTintByアクションを使用するときにいくつかの問題に気付きました。
これにより、CCActions に対する現在のアプローチと理解に疑問を抱くようになりました。
例えば。以前は、新しいアクションを実行するたびに [self stopAllActions] を呼び出していましたが、これは CCTintBy アクションの使用法に静かに適合しません (そのアクションも停止し、スプライトが半分色付けされたままになり、基本色が逆に変更されます)。関数は、stopAllActions によって停止されたとして呼び出されませんでした)。
私のプロジェクトで最も一般的なアクションを残します。アクションがまだ実行されていない場合は、stopAllActions を呼び出す代わりに、特定のアクションのみを停止することを考えていました。これは良い習慣でしょうか?
-(void) runExplosionAnimation
{
[self stopAllActions];
//here should verify if the action is not already running and if so stop it
//To do so I should have a member variable like: CCAction * explosionAnim = [CCSequence actions: [CCAnimate actionWithDuration:0.4f animation:anim restoreOriginalFrame:false], [CCHide action], nil];
//Plus a boolean to distinguish if it is already running..
CCAnimation* anim = [[CCAnimationCache sharedAnimationCache] animationByName:@"bbb"];
if(anim!=nil){
[self runAction:[CCSequence actions: [CCAnimate actionWithDuration:0.4f animation:anim restoreOriginalFrame:false], [CCHide action], nil]];
}
else{
[self loadSharedAnimationIfNeeded];
}
}
CCTintBy アクションがまだ実行されているかどうかを判断するためにブール値を使用する方法は、CCTintBy アクションを再度呼び出す前に元の色を手動で復元することです。
-(void) gotHitWithFactor:(int)factor
{
[self runGotHitAnimation];
self.hitPoints -= factor * 1;
if (self.hitPoints <= 0)
{
isAlive=false;
[self runExplosionAnimation]; //Will also set enemy visibility to false
}
}
-(void) runGotHitAnimation
{
//hitAction is initialized as [CCTintBy actionWithDuration:0.1f red:100 green:100 blue:111];
[self stopAction:hitAction];
self.color = originalColour; //Where originalcolour is initialized as self.colour
[self runAction:hitAction];
}