Help with formatting levels

In my game, the process of setting up a new level is something like:

  • Make a new folder with tilesource, tilemap, GO, script for any other setup needed, Lua module with data about the level, and a collection with the level, the player, and the camera
  • Add the level name to the list of levels and manually require the Lua module, since you can’t do that in a loop
  • Add the collection proxy into the main collection (subject to change)

Are there any better ways of doing this? It seems like my method is too convoluted.

Personally I create levels with a lot of factories. When I need to switch a level I clear everything in the collection and load everything for the next level.
All within one single collection.
And yes, have to mention every lua file for it to get bundled, I do somewhere

if false then
  require('levels.1')
  require('levels.2')
end

and when I actually need level data I do normal require('level.' .. level_id).

3 Likes

I have all my levels in one folder and make Defold include all files in that folder through the game.projecf file. I can’t remember the exact setting name, but I think it’s called “Custom Resources”? Then you can load it from Lua using sys.load_resources().

2 Likes