Godot Version
4.3 rc2
Question
My game has lots of maps. The controls and logic are mostly the same for each map. So i have a play screen Level
that loads the map LevelData
. So far so good.
var packed_scene = load(Globals.level_name)
var play_area = packed_scene.instantiate()
%LevelData.add_child(play_area)
LevelData
is expected to have certain objects with certain names. Specifically path start and end points. Which are Sprite2Ds. When the Level
loads the LevelData
it grabs those objects and builds a path.
terrain_tilemap = %LevelData/Map/GroundTileMapLayer
blocker_tilemap = %LevelData/Map/WallsTileMapLayer
group_1_start_marker = %LevelData/Map/Paths/StartGroup1
group_2_start_marker = %LevelData/Map/Paths/StartGroup2
group_1_end_marker = %LevelData/Map/Paths/EndGroup1
etc.
All of this works. But it’s hard coded to exactly 2 entrances and exits. i want this to be configurable but for the life of me i can’t think of an elegant way to do this.
Things i’ve considered:
- Put the start/end nodes in groups (start, end). But i don’t think group order is guaranteed so i wouldn’t know how to tie them together.
- Store the points and mappings in a dictionary. But that’s not a node, it’s code. Not sure how
Level
could get access to code onLevelData
. - Assume a max of 5 start points, allow them to be null, when
Level
loads the map it checks each of the expected names to see if they exist. Which works but it’s so ugly.
The whole “Godot likes composition through nodes” thing is taking me a while to get used to.