cocos2d start / stop running Scene

馋奶兔 提交于 2019-12-11 07:48:15

问题


I'm trying to load one scene. This runs fine the first time, but when I try to reload again appears a white square where the animation is placed.

This is the code to start and stop the scene. What I'm missing?

thanks.

-(void)runScene:(OTAnimationCC2d *)animation
{
    scene = [CCScene node];

    [scene addChild:animation];

    if ([[[CCDirector sharedDirector] runningScene] isRunning])
    {
        [[CCDirector sharedDirector] replaceScene:scene];
    }
    else
    {
        [[CCDirector sharedDirector] runWithScene:scene];
    }

}
-(void)stopScene
{
    [[[CCDirector sharedDirector] runningScene] stopAllActions];
    [[[CCDirector sharedDirector] runningScene] removeAllChildrenWithCleanup:YES];
    [[CCDirector sharedDirector] pushScene:scene];

}

回答1:


Why not just call [self runScene] at the end of stopScene rather than [[CCDirector sharedDirector] pushScene:scene]? It sounds like you want the scene to reload fresh, which your runScene already does when it calls replaceScene.

Either way you should be creating a new scene node and using replaceScene (which is being done in runScene and is why I recommend just calling that).



来源:https://stackoverflow.com/questions/9418791/cocos2d-start-stop-running-scene

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!