Fixed screen, how to walk to next "room" ?

TcheyTchey Posts: 52Member


I try to understand how can i move the player from one screen to another, when walking on a specific tile.

What should i read, or watch, to learn ?

Here is what i have so far. Fixed view, where the player can move in 4 directions and interact with signs. The bottom part is fixed and show texts from interactions. The right part is fixed and (will) show different menus (grab, inventory, options...). Lights are for testing shadows and occlusions.

I'd like to change "room" when i walk on the arrow to the right.


  • PCMXMSPCMXMS Posts: 67Member
    edited September 2016

    I would do something like this:
    Area2d to detect if the player is over the arrow (or at that part of the screen)
    If it is, load the new scene on the right (in this case)
    Make a little transition from one screen to another (like the camera moving to the right)
    After centering the new screen, I would destroy the scene to the left.

    Bear in mind that this is not the only existing method. Also, it might not be the most optimal solution.

  • TcheyTchey Posts: 52Member

    I didn't find tutorial i could understand about Area2D

    However, i manage in the meantime to get an ugly but functional splash welcome screen, and a main menu leading to "play" and "quit"... One day to understand this part...

    I suppose there is a relation between "starting the game by loading the first room", and "walking to next room", but i don't get it yet.

    Also i don't want to destroy the rooms, they are not "stages" or "levels", but more like rooms inside a house, you can go to in and out many times.

  • RossRoss Posts: 199Member
    edited September 2016 Answer ✓

    Area2D has a bunch of signals. The most useful ones are 'body_enter' and 'body_exit'. They will fire whenever a body enters or exits the area, and give you a reference to the body. For this case you just need to connect body_enter to a "switch room" function in your script.

    You can connect signals in 2 ways.

    1. In the editor - select the Area2D node and go to the 'Node' panel under 'Signals'. Double click a signal or click the "Connect.." button to connect a signal.

    2. In script - use the connect() function. I prefer this because it makes them easier to keep track of. If you connect signals in the editor you will end up with functions in your script that are never called from that script. If you connect it via script you can search the script for the function and find out where it came from.

    When PCMXMS said "destroy" the previous room, he didn't mean delete it forever. Presumably you will have a scene file for each room. When you want to switch rooms, you would load() the new room's scene file, create a new instance of it, and then queue_free()("destroy") the old scene since you're not using it any more. If you walked back through the doorway to that old room, it would be loaded again, just like it is in the beginning.

    One day to get a functional splash screen and main menu isn't bad if you're not used to the engine yet. Unfortunately the documentation is not great. Once you learn how to do things you'll do the same work in an hour or less.

  • TcheyTchey Posts: 52Member
    Answer ✓

    Thanks, combined with this video i managed to understand it.

Sign In or Register to comment.