The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Currently I am working on a top-down 2D game where the player explores a randomly generated dungeon. When the dungeon is generated, each room is a premade scene with set entrances and based on the layout generated, the program will go to each room in the generated layout and place a premade room with the same 'links' (doors or tunnels).
I use gdscript by the way.
Instead of instancing each room in one big scene, I would like the whole scene to change to the room scene based on which room the player is in.
Currently all rooms are in 1 big scene with stand-in rooms and the camera changes to a camera fixed on the room the player is in for prototyping. If you imagine the Binding of Isaac with the rooms being blank with a white outline then that is exactly what it looks like right now.
The program DOES save what room is adjacent to it in a dictionary (replacing null if there is a room and staying null if there isn't a room) like below:

var connectedRooms = {
    Vector2(1, 0): null,
    Vector2(-1, 0): null,
    Vector2(0, 1): null,
    Vector2(0, -1): null,

I just don't know how to change scene as I cannot write 'change scene to this path when enter here' as the path I want the scene to change to technically hasn't been made yet.
I was wondering if maybe I put something like 'if enter this area (the exit) change scene to this room in dictionary' but I don't know exactly what code to put in.
I'm also worried that if I do do 'if enter this area (the exit) change scene to this room in dictionary' then I don't want the character to be entering the same scene when it is actually two different rooms using the same room layout so would I have to do something with .duplicate()?
Thanks in advance.

Godot version v3.2.3.stable.official
in Engine by (12 points)
recategorized by

1 Answer

0 votes

I don't think this is good way to go. Changing scene to each room will force You to save and load entire pattern of rooms visited before and overall room map. I would make scene overlay, scene of room wouldbe active, but a scene of whole corridor would be hidden and would not be freed.

Whatever You choose, the answer for question about dynamic scene instantiating is quite simple. Just create one scene of "room" and make it have variables indyvidualizing its layout in script. For example this pseudocode :
var r = preload(res//room)
var room = r.instance()
r.trapsamount = randomnumber * difficulty
r.doors = some number passed by corridor scene
r.monsters = etc etc
r.tilemap = randomly generate anew

Something like this. This can also be done with New() and init() constructor combo, no big difference

by (8,188 points)

The reason I want to load each room is because the ‘room’ doesn’t necessarily only consist of one room and some will be about 4 viewports large. Is it still a good idea? I don’t know how difficult it is for the engine to load scenes. What is a scene overlay?

loading is not a problem for engine, You can eventually be worried about keeping both scenes active at the same time, which could be dangerous for framerate. This will not be a problem as long as You make sure that scene of whole corridor does not process anything while the camera is zoomed on one active room.

There is no such thing as scene overlay, I just used that word and explained what I mean :). And i will repeat - it is not to change scene form one to another, but keep both scenes, one is hidden, another is playable and zoomed by camera.
Take Heroes of Might and Magic for example. When combat happens, the world with castles and stuff don't disappear, they are in the background. Scene is not CHANGED into combat, because every time combat occurs all that world information would have to be kept and recreated again after combat.

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 Frequently asked questions and 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 [email protected] with your username.