i am new on cocos2d, I have
int score;//default 0
I am increasing the score but when switch scene, score is going to be 0 again. How can i keep the score when i switch the scene?
Sorry for my bad english.
Best Regards. Thanks for your advice.
i am new on cocos2d, I have
int score;//default 0
I am increasing the score but when switch scene, score is going to be 0 again. How can i keep the score when i switch the scene?
Sorry for my bad english.
Best Regards. Thanks for your advice.
You are storing a score in a scene - perhaps this would be better stored in a single location that all of your scenes can access? After all, your scene should be concerning itself with managing your views and user interaction rather than game logic.
There are many approaches for this: will there only be one game happening at once? If so, perhaps a singleton would be a good way to manage this data.
If not, you will need a reference to the score in each scene (that is to say, each scene would need a public variable that the previous scene can transfer the score value to before presenting).
NSUserDefaults is a good way to store simple global data, especially if you want to persist it across application launches.