[Solved] Player position when switching rooms with global variable?

Hi guys I’m making a lateral 2d game and I would like to know possibly with visual examples how to set the X and Y coordinates of the player in a global variable.

you just go to Add action → Other actions → Variables → Global Variables → Change Number Variable. You just give a name to your variable (you need 2 variables , one for the x- and one for the y-position) and set it to the position of your player - you can use the expression-builder for that (the blue button with the sum sign and 123).

And then it would look something like:
global variable

OK thank you.
Do you have to enter the two variables for each scene?

The variables are global and are available in all of your scenes once you have declared them.

Hi here are some screenshots but the player can’t pass the third scene

In your event, the first line in the actions is to change the scene. The following two lines, where you get the position of the player, are then not executed anymore. In Gdevelop the actions are performed always from top to bottom. So you need to get first the x- and y-position and then change the scene (all in the same event block).

I’m new and I don’t know how to use these variables, there aren’t any examples and videos about it

Alright, so did you manage make it work? It should look something like:

And that’s what you can do in your next scene:

Yes it works I have to fix a few things like for example the size of the character to the next scene.
Thank you

1 Like

Another question now when the character passes to the next scene it appears with the original dimensions like 610 x 523 I had resized it to the second scene 116 x 104 :grin:

Okay, what is your problem. If it is about the position, you could divide the x- and y-position by the scale-ratio from one scene to the other. You can also scale the player-sprite if necessary.

At the moment your ratio is a bit strange 610 / 116 = 5.258620689… I would recommend to choose something that scales better. If you have pixel art you need to consider the scaling ratio well to avoid pixel distortions.

My player from the first second scene resized it with width from 610 to 116 and height from 523 to 104 when I change scene the player size returns again to 610 width and 523 height


Could you post your events?

the dimensions of the character of the second scene must be identical also in the third scene and so on

I see. In this case you have to scale the player sprite for every scene individually to the size you actually need, or alternatively you could have different sprite-object sizes for each scene. I know this is quite tedious but your sprite-object is not automatically adjusting to a different scene size.

Ok how can I resize it for each scene individually because from the second to the third scene with create object the player regains the original dimensions

For each scene you have to do something like this (with the relative values for each scene):

Ok perfect thanks again you’re a friend

1 Like

hey im having the same problem i tried to do what y’all said but still it wont work when entering like a house or a shop everything i okay but when i went out to go to the main scene here where is the problem my player just return back to his original
X and Y cordinates with everything that he collected back again plz i need your help its been 2 days and im still stuck in this if u want i can give my discord id so any one can help plz
an thank you <3

Hi, could you post your events and explain what exactly should happen? You enter a room, get out of there to the main scene and then you want to be where?