cocos2d启动/停止运行场景

发布于 2025-01-08 18:49:59 字数 671 浏览 4 评论 0原文

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

这是启动和停止场景的代码。我缺少什么?

谢谢。

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

}

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

莳間冲淡了誓言ζ 2025-01-15 18:49:59

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文