cocos2d启动/停止运行场景 [英] cocos2d start / stop running Scene

查看:130
本文介绍了cocos2d启动/停止运行场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在载入一个场景。第一次运行正常,但是当我尝试重新加载时,会出现一个白色的正方形,放置动画。

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?

感谢。

-(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];

}


推荐答案

只是在 stopScene 结束时调用 [self runScene] ,而不是 [[CCDirector sharedDirector] pushscene:scene] ?它听起来像你想要的场景重新加载新鲜,你的 runScene 已经做了,当它调用 replaceScene

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.

你应该创建一个新的场景节点,并使用 replaceScene (这在 runScene ,这就是为什么我建议只是调用)。

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).

这篇关于cocos2d启动/停止运行场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆