Is it possible to detect which CCScene is currently showing on the scene? I have 2 CCScenes in my game and I want a certain action to occur if one is showing.
Also quick related question, if I wanted to check if a CCMenu is not showing currently would I do something like
if (!menu) {
//Menu is not showing currently
}
I am a bit of a noob when it comes to Cocos2D so please forgive me :)
Thanks!
You can use the CCDirector to tell which scene is running.
As for whether the menu is showing. You would have to check with the parent of the menu. If the parent where your CCLayer, then you could check by
If the menu is child of some other node, you can get the parent through a similar method and get a reference to the menu.
If the
menu == nil
, it is not showing.UPDATE
In cocos2d, you are discouraged from keeping references to all of your sprites, instead you should be giving each node a unique tag and use that to reference it. To achieve your first goal, you can give your scene a tag in your 2 respective CCLayer classes.
You can set up your unique tags in an enum in a file called Tags.h, then import that into any classes that need access to your tags
Example Tags.h
Then in your layer class
Now when you grab the current scene you can check against the tags
The
tag
property is fromCCNode
which is the base class ofCCLayer
,CCScene
,CCSprite
,CCMenu
...