A system to design and load levels

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Luka38
:warning: Old Version Published before Godot 3 was released.

Hi everyone!
I’m making my first game in Godot and have a bit of a conundrum since I have never made a game with changing levels and have no idea how to approach it.
The game is a 2D platformer with different levels that have a static camera that covers the whole room in the viewport. The Player will be “teleporting” to other levels when he reaches exit points of each levels .
My idea was to lay out the whole game in a single scene, so I can easily edit each levels and see how does it compare to next/previous levels. But loading the whole game on runtime doesn’t seem to be a very good idea performance wise :smiley:
So what’s the best approach to design the game and have all the levels and platforms in the same scene, but when running the game to have it individually load when enter that level.
All of the platforms are moving Kinematic Body scene’s, levels should only change their background sprite that’s animated, and the “exit points” are just going to be Area nodes with animated sprite.
If anyone has a totally different way they would approach, please tell me, it’s always better to hear many different opinions :slight_smile:
Here’s a rough draft of how the game should look:
enter image description here

:bust_in_silhouette: Reply From: eons

Don’t think of performance until you get performance problems.

Just get_tree().change_scene should be fine.

Later you can preload levels on an autoloaded script or instance the levels on a node that manages the levels.

But as a first step, I suggest to make the quickest way which is changing scenes (faster to test levels too).

My idea was not actually “change scenes” per se, but to layout all my Levels in a single Scene, in which I would just teleport Player from one exit point to an enter point for the next Level.
As pictured above, all of the levels will visible in the Main Scene of the entire game and the Player will be a child of that Main Scene, and so will the other Levels.

Main Scene
-Level_00
—Enter_Point_00
—Platforms_00
—Exit_Point_00
-Level_01
—Enter_Point_01
—Platforms_01
—Exit_Point_01
-Level_02
—Enter_Point_02
—Platforms_02
—Exit_Point_02
—Exit_Point_02b
-Level_03
-Level_04
-Player

This way, at least I think, would be much quicker to test out Levels and a more visual way to see how they compliment each other.
But I don’t think having hundreds of objects from the entire game, running their code every single frame would be a good idea for performance :smiley:
Is there a way to load all objects from a Level only when needed (when player reaches them)?
Or maybe this approach is a bad one, I don’t know… thoughts?

Luka38 | 2017-10-26 12:24

You can have a list of levels (paths) on an array, and load them when needed, for small things it should be fast (or instance+add current, preload the next).

Also, instanced scenes can be changed into “InstancePlaceholder” (check instanced menu) and instance them when needed.

For styles more metroidvania, your “entry/exit points” can have a reference to the next level and load/preload them on ready, once loaded, the instancing+adding is nearly immediate.

If each level is huge, the level structure may need some extra partitioning, like preloading entry points first and doing background loading of the rest while playing, also freeing old level data in chunks.

eons | 2017-10-27 00:33