+1 vote

Hi there,

I am currently trying to make a 2D RPG pixel game. I am an artist trying to learn programming. Im getting there i think :")

I have made a scene changer.
Once the player enters the area, a signal is sent, that body has entered and it transitions to the scene i have assigned.
My Scene_changer code below:

extends Area2D

export (String, FILE, "*.tscn") var scene_target = ""

func _ready():

$Sprite.visible = true

func onscenechangerbody_entered( body ):



That scene that i have assigned, has its own scene changers and each one goes to a different scene.
You can equate this to a player being in a city, then exiting a city that goes on a main map, that has different cities to choose from and to go to.


Entering and exiting a house.

example from the game Shovel Knight:
enter image description here

The problem that i cant find the answer to is:

In every city that i have, there are 4 exits, North, South, East and West.
When the character exits through the North side , to the main map, the character's position, is not on top of that main map city point that it came out of. And the same thing can be said for when it returns to the city it came out from, it does not enter from the North side. Which is understandable as it is not coded in.

How would one go and make it so that it enters through the exit and vise versa and not at a random point.


Ive been on this problem for the last 2 weeks, ive search online alot and cant seem to find an answer.

Thank you in advance for helping me.

in Engine by (13 points)
recategorized by

1 Answer

+1 vote

Without knowing the exact details of your project, I can only offer the following technique.

You can have a Singleton scene (also called AutoLoad) that keeps track of which city the player is in and which exit he uses. A singleton is a global node that is always present in your project. You can use it to store information that you want to survive from scene to scene.

You can also have a dictionary there that has exit names as keys and apppropriate destination positions as values.

When you call your code to change the level/scene, you can use the current exit and the dictionary to position the player on the new map at the correct position.

by (1,533 points)
edited by

Thank you very much for the reply :).

That sounds like a good idea, I will look into this Singleton scene Autoload thing.
I think this might be my only option.

I am going to leave this question for a couple of days to see if there are more ways to solve this one problem.

Again thank you very much.

No problem. I use variants of this method in a lot of my projects. It works quite well.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.