+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
pass

func onscenechangerbody_entered( body ):

gettree().changescene(scenetarget)
get
parent().queue_free()

.

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.

OR

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.

asked Apr 7, 2018 in Engine by marios (13 points)
recategorized Apr 7, 2018 by marios

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.

answered Apr 7, 2018 by Diet Estus (1,493 points)
edited Apr 7, 2018 by Diet Estus

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.