【问题标题】:cocos2d start / stop running Scenecocos2d 启动/停止运行场景
【发布时间】:2012-02-23 18:16:32
【问题描述】:

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

这是启动和停止场景的代码。我错过了什么?

谢谢。

-(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 结束时将场景推回自身。

标签: cocos2d-iphone scene


【解决方案1】:

为什么不在stopScene 的末尾直接调用[self runScene] 而不是[[CCDirector sharedDirector] pushScene:scene]?听起来您希望场景重新加载新鲜,您的 runScene 在调用 replaceScene 时已经这样做了。

无论哪种方式,您都应该创建一个新的场景节点并使用 replaceScene(这是在 runScene 中完成的,这就是我建议只调用它的原因)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-23
    • 2013-06-10
    • 1970-01-01
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多