How Do I Pass An Integer Between Scenes?

How Do I Pass An Integer Between Scenes?
0.0 0


Hi all,

I’ve done a world select menu scene which then leads to a level select scene. Both of them using the SlidingMenu.h that has been provided on the forums. I’m using Cocos2d-x 2.0.1 at the moment.

At the moment i’m using something like this.

@ CCMenuItemImage *world1 = CCMenuItemImage::itemWithNormalImage(

The code above takes me to my levels scene happily.

If i try using another callback function that i’ve created like:
virtual void menuEnvironmentSelected(CCObject* pSender, int environmentID);

But it won’t compile. How do I pass an integer between scenes? I want the integer to be based on the item that is selected from the menu which will then choose what background image will be used in the level select scene. Any help would be appreciated.




I’m still not diving into scenes but I ran into a similar problems with callbacks and I can’t help much because I can’t see your callback function’s code.

You could either have a member variable called m_NextSceneID or something and when a certain level is selected, have some IF branches to check which scene to run OR have the next scene have a public method called setID( int p_ID ) and after you create the scene object ( but before you switch to the scene) use setID( ) to pass that number onto the scene.


Create a singelton GameConfig class and save global game config data. Done.