从挂起的应用程序状态返回时,哪个 cocos2d 场景当前处于活动状态
环境是支持多任务的 iOS 设备,例如 iPhone4。 我在一个 cocos2d 应用程序中,其主菜单可通往多个场景。
如果我使用任务栏切换到另一个应用程序,然后切换回来,我如何以编程方式判断哪个场景是积极的?
The environment is an iOS device with multitasking support, like an iPhone4.
I'm in a cocos2d app with a Main Menu that leads to several Scenes.
If I switch to another app using the taskbar, then switch back, how do I programmatically tell which scene is active?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能在应用程序委托的 applicationWillEnterForeground: 方法中检查 CCDirector 的 runningScene 属性吗?如果您对 CCScene 进行子类化,则只需检查场景的类,否则您可能需要向每个场景添加某种其他类型的标识符。
Couldn't you just check CCDirector's runningScene property in your app delegate's applicationWillEnterForeground: method? If you subclass CCScene you could just check the scene's class, otherwise you may want to add some other sort of identifier to each scene.
您可以为 CCSCene 类添加一个标识符,例如
int sceneID
或typedef enum { mainMenuID = 0, playSceneID, helpSceneID, aboutSceneID } sceneID
,然后只需将其中的每一个分配给每个场景的init
方法...然后您可以在applicationWillEnterForeground:
中检索它,如下所示:int theSceneID = [[[CCDirector sharedDirector] runningScene] classID] ;
但就像 Zaid 建议的那样,使用 CCScene 标签要容易得多。
you could add an identifier for the CCSCene class such as
int sceneID
ortypedef enum { mainMenuID = 0, playSceneID, helpSceneID, aboutSceneID } sceneID
and then simply assign each of these in theinit
method of each scene... then you can retrieve it inapplicationWillEnterForeground:
like so:int theSceneID = [[[CCDirector sharedDirector] runningScene] classID];
but like Zaid suggested, it is alot easier to use the tag of CCScene.