应用程序终止后如何恢复到正确的层(cocos2d)

发布于 2024-11-28 10:18:33 字数 397 浏览 1 评论 0原文

您好,我需要有关此代码的帮助。在我的游戏中,我有一个主层,其中有用于选项和游戏级别的菜单按钮。 我有一个游戏层来玩游戏。

当我通过单击主页按钮终止应用程序并再次重新启动游戏时,它从我离开的正确位置开始。

我的问题是,当我在游戏层终止时,我想在恢复时启动恢复/暂停层,而当我在主层终止游戏时,我不想启动恢复/暂停层。我怎样才能做到这一点?

目前这是我的代码。

- (void)applicationWillResignActive:(UIApplication *)application {
[[CCDirector sharedDirector] pushScene:[PauseScene scene]];
}

我希望有人能帮助我,因为我仍在学习 ios 编程

Hi i need help with this code. In my game i have main layer which has menu button for options and game level.
And I have a game layer to play the game.

When I terminated the app by clicking the home button and i relaunch the game again,it starts in the correct spot i left.

My questions is when i terminate in the game layer i want to launch a resume/pause layer when it resumes, and when i terminate the game in the main layer i dont want to launch resume/pause layer. how can i do that?

currently here is my code.

- (void)applicationWillResignActive:(UIApplication *)application {
[[CCDirector sharedDirector] pushScene:[PauseScene scene]];
}

I hope someone can help me coz im still learning on ios programming

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

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

发布评论

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

评论(1

任性一次 2024-12-05 10:18:33

尝试用这个:

- (void)applicationDidBecomeActive:(UIApplication *)application {
    if (nil != [[[CCDirector sharedDirector] runningScene]) {
        // make sure we have a scene to release, 
        // since this method is invoked on start up, too
        [[CCDirector sharedDirector] popScene];
        [[CCDirector sharedDirector] resume];
    }
}

- (void)applicationWillResignActive:(UIApplication *)application {
    [[CCDirector sharedDirector] pushScene:[PauseScene scene]];
    // pause CCDirector, so we can keep any scheduled events for later
    [[CCDirector sharedDirector] pause];
}

Try with this:

- (void)applicationDidBecomeActive:(UIApplication *)application {
    if (nil != [[[CCDirector sharedDirector] runningScene]) {
        // make sure we have a scene to release, 
        // since this method is invoked on start up, too
        [[CCDirector sharedDirector] popScene];
        [[CCDirector sharedDirector] resume];
    }
}

- (void)applicationWillResignActive:(UIApplication *)application {
    [[CCDirector sharedDirector] pushScene:[PauseScene scene]];
    // pause CCDirector, so we can keep any scheduled events for later
    [[CCDirector sharedDirector] pause];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文