views:

153

answers:

2

Hello, 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

+1  A: 

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.

Colin Gislason
Thank you for your help however, when I try to pop the scene, after pushing it, the application ends, any suggestions?Thank you
nonono
sorry, I have it working now, Thank you.
nonono
A: 

Hey Colin, the Scene that we send to back, is it still working ? Or all of animations on it will be "pause" as long as it stays in back of the current scene ?

Obelisk Do