2011-09-04 74 views

回答

1

您可以隨時添加一個方法來指示何時結束該方法,然後切換某些BOOL或類似的東西,以表明它沒有運行,並投入了啓動方法來切換BOOL表明它開始:

id actionMove = [CCMoveTo actionWithDuration:actualDuration 
position:ccp(-target.contentSize.width/2, actualY)]; 

id actionMoveDone = [CCCallFuncN actionWithTarget:self 
selector:@selector(spriteMoveFinished:)]; 

id actionMoveStarted = [CCCallFuncN actionWithTarget:self 
selector:@selector(spriteMoveStarted:)]; 

[target runAction:[CCSequence actions:actionMoveStarted, actionMove, actionMoveDone, nil]]; 

here.

改性在兩種@selector方法:

-(void) spriteMoveStarted:(id)sender { 
    ccMoveByIsRunning = YES; 
} 

和:

-(void) spriteMoveFinished:(id)sender { 
    ccMoveByIsRunning = NO; 
} 

其中ccmoveByIsRunning是我指的是BOOL。

編輯:正如xus指出的那樣,您應該不會這樣做,而應該使用其他人指出的[self numberOfRunningActions]

+0

這是一個醜陋劈,[自numberOfRunningActions]應該使用(如下面註釋) – xus

+0

@xus : 好點子。我的壞,我不能刪除答案,因爲他已經接受了,但我指出了我的錯誤,謝謝! – Dair

6

您可以在任何CCNode使用[self numberOfRunningActions]。對你來說,這聽起來像你想知道是否有任何簡單的運行或不動作,所以它不是一個大問題,以知道確切的數字事前。

5

我們可以很容易地檢查是否採取具體行動,通過使用getActionByTag方法和action.tag性能運行。 沒有必要引進CCCallFuncN回調或計數numberOfRunningActions

實施例。

在我們的應用程序中,重要的是讓jumpAction在執行另一個跳轉之前完成。爲了防止已經運行的跳躍行動期間觸發另一跳躍 代碼的臨界跳躍部分被保護爲如下:

#define JUMP_ACTION_TAG 1001 

-(void)jump { 
    // check if the action with tag JUMP_ACTION_TAG is running: 
    CCAction *action = [sprite getActionByTag:JUMP_ACTION_TAG]; 

    if(!action) // if action is not running execute the section below: 
    { 
     // create jumpAction: 
     CCJumpBy *jumpAction = [CCJumpBy actionWithDuration:jumpDuration position:ccp(0,0) height:jumpHeight jumps:1]; 

     // assign tag JUMP_ACTION_TAG to the jumpAction: 
     jumpAction.tag = JUMP_ACTION_TAG; 

     [sprite runAction:jumpAction]; // run the action 
    } 
} 
+0

感謝您使用這種檢查方法來查看某個操作是否正在運行。我的成千上萬行代碼的應用程序有一個巨大的故障,最終由您的代碼中的方法修復。謝謝。 –

相關問題