In my cocos2d project, I have two scenes. I transition between the two using CCDirector's replaceScene. Is it possible to save the state of the current scene so that when the scene is changed to a different scene, and then changed back to the original, all the objects and variables in the original are the same.
Thank you,
nonono
Instead of using replaceScene
, you can use pushScene:
and popScene
. pushScene:
puts the new scene onto a stack and displays it. When you are done that scene, call popScene
to return to the previous scene on the stack.
[[Director sharedDirector] pushScene: newScene];
//...
[[Director sharedDirector] popScene];
Note that this does leave your previous scene in memory (as you asked), so it is recommended to use replaceScene:
if you possibly can. If you do use pushScene:
and popScene
, it is best to keep your scene stack pretty small.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With