Which cocos2d scene is currently active when returning from suspended app state
The environment is an iOS device with multitasking support, like an iPhone4. I'm in a cocos2d app with a Main Menu that lead开发者_JAVA百科s to several Scenes.
If I switch to another app using the taskbar, then switch back, how do I programmatically tell which scene is active?
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.
you could add an identifier for the CCSCene class such as int sceneID
or typedef enum { mainMenuID = 0, playSceneID, helpSceneID, aboutSceneID } sceneID
and then simply assign each of these in the init
method of each scene... then you can retrieve it in applicationWillEnterForeground:
like so:
int theSceneID = [[[CCDirector sharedDirector] runningScene] classID];
but like Zaid suggested, it is alot easier to use the tag of CCScene.
精彩评论