About changing scenes

Hello!
I’ve just started to do a menu system and I need some help with understanding of some things.
As far as I’ve understood the whole game is divided into scenes.

  1. Am I right if I think that each state of menu is a different scene ? For example, I have 3 menu items at the beginning: NewGame, Shop, Exit. And I chose the “Shop”. Should I create a new scene to the new interface of shop ?

  2. You see, I can’t get the idea of working with scenes at all. For example, there is a scene that I have just created. And I want to move to a new scene. I have 2 variants of acting:
    a) I could do replaceScene and, as far as I understood, this will release the previous scene with all its data.
    b) I could use pushScene/popScene. But in this case I don’t understand how to leave the main scene in memory without deleting its data. And again example:
    the simple process in the game: menu > GameProcess> menu > GameProcess> menu -> exit;
    in the code it will be like that:
    pushScene(menu);
    pushScene(GameProcess);
    popScene();
    pushScene(GameProcess);
    popScene();
    popScene();

But I don’t want to recreate GameProcess scene each time I move back to menu! What could I do ?

Thanks in advance.

Hi, you can put all elements of menu scene into one MenuLayer. Menu scene owns the MenuLayer, using replaceScene to switch to game scene, and when your app need to be return to menu scene, you just need to create an new MenuLayer and add it into game scene. Therefore, the gamescene will not be released. When you don’t need the menulayer, you should make it invisible or remove it from game scene. Hope this can help you. Does anybody have a better idea? :slight_smile:

Hi!
Thanks. May be it’s the solution but may be not very flexible, because I may have several scenes which may follow one after another and to remain far back from the MainScene. Actually I’ve found the solution which I think not very bad: I’ve created a LoadManager who can load the resources I need into cache manager and it cause resources to remain in cache until I told it to release. There is also a layer between one scene and another which I can use to:

  1. show the progress of loading.
  2. switch to a lightweight scene to remove previous scene and switch to next scene.

It may seem little bit harder but it really works and not so bad desicion in my humble opinion. :slight_smile: