Hey! Long time pixel artist, amateur dev here.
For my first real game I’m working on a platformer. Surprisingly mostly smooth sailing with the help of tutorials but I’m stuck now.
I want my game to have multiple rooms and levels and I’m struggling to transition my player character between them. Obviously change scene does just that, without carrying over any information. I realised that scene variables needed to be changed to global so I can carry money/score over but instance variables like my players health is reset. I’m also un able to work out how to have the player spawn at the correct coordinates (ie. the door that connects to the door from the last scene).
Is there a way to just send one object (my players), instance variables and all to specific coordinates in another scene? Or will I have to set up global variables for the health too? If this is the case, would I have to use global variables to somehow store coordinates for transitioning and if so, how do I go about this?
Sorry for the long winded question, and thank you in advance.
Peace out x
i have not try this yet, but is your player a global object?
if you use variables, like player health as a object variable of your player, they might transition over scenes.
ether way, you have to change your variables to something globally accessible.
as for positioning you store the X/Y positions in global variables and on transition to the next scene
at the beginning of the scene
change player position to global variable X/Y
A tip on how to transition using doorways (or any object) is to add two variables to each doorway instance object called “name” and “destination”. When the player collides with a doorway object (before doing the scene transition) set a global variable called something like “nextDestination” to the value of “destination” on the doorway. Then after you load the new scene, select the doorway object in the new scene that has a “name” that equals “nextDestination” and set the player starting coordinates to the (x,y) position of that doorway object.
This is a data driven model with simple logic, so when you are designing the levels you’ll need to ensure you always put good values on your doorway objects.
I hope this helps.
Parts of your answer make sense but I feel like I’m missing some key bits here. Are there any example projects of this about I could take a look at? I’m slightly confused about setting the global variable while transitioning, and how that works. And how I’d even set the player starting coordinates.
Thank you for your detailed response, sorry if I sound like an idiot, very new at this kind of thing.
Scene variables to global variables goes like this.
At the beginning of the new scene the same thing backwards.
But it is better to use global variables directly if you want to use the values in different scenes.
You can just save a number for the door connection.
And have a object/instance variable for the door identification.
In the new scene you spawn automatically at door 2.
(If you use a separate object for each door, you don’t need this veribale.)
Amazinggg, thank you!! I get it now.
Thanks for your help everyone!