|Topic was automatically imported from the old Question2Answer platform.
I’m making a rogue-like game. like Binding of Isaac. As far as I know, Isaac creates a scene for each room, and when you go to the next room, you go to the next scene, and when you go to the previous room, you go to the previous scene.
Is there a way to leave the previous scene’s resources as is and go to the next scene, or have the next scene go to the previous scene in the same way?
For example, the room looks like this. Should I put all the rooms in the Autoload variable?
Sorry to my horrible English.
if you change your scenes with
change_scene methods then you can’t save previous scene easily. But you can implement your own scene switching algorithm:
Main node that will act as scenes container.
- Load your scene using
add_child methods to
- When next scene is required, you can remove your scene from
Main node using
remove_child method and then repeat step 2 to get new scene going. This way you still have reference to previous room and can do anything you want with it. But always remember to
queue_free nodes when you don’t need them anymore, otherwise, if you lose reference to it, it will result into memory leak.
Note that this is just one of the many ways of implementing scene switching algorithms and optimal solution depends on your game.
Loading rooms into Singleton class (autoloading variable) can be very bad solution. I suggest you to avoid this approach.
Thank you! I was trying to do it with a singleton, but I canceled it and did it differently.
HorseGorilla | 2021-07-22 17:11