Search code examples
objective-ccocos2d-iphone

How to call block after particular action is finished?


I have boolean parameter BOOL isMoving. I want to set this parameter to FALSE after particular action finishes running. My code looks like this:

CCActionMoveTo* actionMove = [CCActionMoveTo actionWithDuration:1.0f position:[self GetPosition]];
CCActionCallBlock* blockUpdate = [CCActionCallBlock actionWithBlock:^{isMoving= FALSE;}];
CCActionCallFunc* actionCallFunction = [CCActionCallFunc actionWithTarget:nil selector:@selector(accessDelegate:)];
CCActionSequence* seq = [CCActionSequence actions:actionMove,blockUpdate,actionCallFunction, nil];
[self runAction:seq];

unfortunately neither blockUpdate nor actionCallFunction waits till actionMove is finished. Please help


Solution

  • Both blockUpdate and actionCallFunction do wait for actionMove to finish with the code you provided.

    The only explanation I can offer is that a move action that moves to the same location the node is currently at is simply ignored, since the node "is already there". Your use of [self GetPosition] seems to indicate that the move action moves the node to its current location:

    CCActionMoveTo* actionMove = [CCActionMoveTo actionWithDuration:1.0f position:[self GetPosition]];
    

    If that is not the case try replacing the move action with a CCActionDelay action to just wait for n seconds.