Changing to next scene after an animation ends. cocos2d

147 Views Asked by At
-(void)test:(CCMenuItemSprite*)item
{
    [item runAction:action];
    [[CCDirector sharedDirector] replaceScene:sceneToRun];
}

how do i make it so that item completes the action before the scene gets replaced? Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

You would do something like:

CCScene* sceneToRun = ...;
CCMenuItemSprite* item = ...;
id action = ...;

id changeSceneAction = [CCCallBlock actionWithBlock:^
{
    [[CCDirector sharedDirector] replaceScene:sceneToRun];
}];

id seqAction = [CCSequence actions:action, changeSceneAction, nil];

[item runAction:seqAction];

Assume the ... represents the creation of the item. If you are using cocos2d 3.0 you would do something like:

id changeSceneAction = [CCActionCallBlock actionWithBlock:^
{
    [[CCDirector sharedDirector] replaceScene:sceneToRun];
}];

id seqAction = [CCActionSequence actions:action, changeSceneAction, nil];

[item runAction:seqAction];

Hope this helps.