动画结束后切换到下一个场景。的cocos2d

时间:2014-05-30 10:10:00

标签: cocos2d-iphone ccmenuitem

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

如何让它在场景被替换之前完成动作? 感谢

1 个答案:

答案 0 :(得分:0)

您可以这样做:

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

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

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

[item runAction:seqAction];

假设...代表项目的创建。如果你使用cocos2d 3.0,你会做类似的事情:

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

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

[item runAction:seqAction];

希望这有帮助。