Here’s an odd one for you. I’m looking to do something similar to what’s found in the sub game demo in order to simplify some logic in my game. Ideally I’d like to transition the player to the “sub game” without them really knowing it’s happening. By that I mean, somehow have the player character maintain any momentum or state they may have between scenes.
I could perhaps serialize the object and pass it to the new scene but that doesn’t seem like it would be very seamless. Any thoughts?
TIA
Edit: I found this thread looking to do something similar.
Sure, I’ll briefly explain my use case. I have multiple scenes running simultaneously that I want an object (Sprite) to be able to move between at will but can only exist in one scene at a time. This could be used for example in a Diablo style game where you can drag an item from the world (main scene) to your inventory (UI scene).
So in my code example, obj could be a sword sprite that is being transferred from scene to scene. As for where the code is placed, it could be in a dragend event or any event where you’d want to trigger the code.
A word of caution, though: that example code is heavily untested and only works for simple objects like Sprites. I’ve since learned that it does not work for nested objects like Containers with Sprites.
thanks for sharing these tricks. might use this in the future when the case arrives
so this already tested when the scene shut down?
i believe it won’t work for container since every object within the container still registered as previous scene object. i believe adding an iteration over the container child should do the trick.
Instead of multiple scenes, would it be possible for you to include each scene’s content in to a separate container?
So there will be one seen with multiple containers representing groups of game objects.
Then it would be easy for you to move player from one container to another.
This is a good thought and may work in most cases. I have many systems that need to be managed during the transition from one context to another that using the Scene lifecycle just makes easier.