Level Editors
There are lots of great level editing tools that exist for designing maps and levels in your games. Here’s an overview of how to use the most common ones.
Tiled
Tiled is a long-standing map editing software. You
can export your maps as Lua files, which you can then require in your Usagi
game code. When you then re-export your level as Lua, it will live update in
your game.
Steps for using Tiled:
- Set up your project and tileset; the tileset should point to
sprites.png - Save your project in Tiled’s tmx format
- Export your map using Ctrl + Shift + E and save it as
map.luaor whatever you want to name it - Then press Ctrl + E after making future changes to quickly
re-export
map.lua
Then in your Usagi game code, you’ll local map = require("map") which gives
you the Lua table of your exported map. You can loop through the data to check
for collisions, draw your map, etc.
View the Tiled example.
It shows how to loop through the layers of a level and draw them with camera
scrolling. The example provides a
tiled.lua
that you can drop into your project and use like: tiled.draw_map(map, camera).
Alternatively, you can also save your Tiled projects using the JSON format
instead of the TMX format in your project’s data directory and import them in
a way similar to LDtk with usagi.read_json.
LDtk
LDtk is a newer map editor. LDtk files contain all the project’s maps/levels and uses the JSON format. Here’s how to use LDtk with Usagi Engine:
- Set up your LDtk project; set up your tileset to poin to
sprites.png - Save your LDtk project in
data/maps.ldtkordata/levels.ldtk - Use
usagi.read_jsonto read your LDtk data:local ldtk_project = usagi.read_json("level.ldtk")
You can then loop through the maps and layers and check for collisions and draw your map.
View the LDtk example.
It shows how to loop through the layers of a level and draw them with camera
scrolling. The example provides a
ldtk.lua
that you can drop into your project and use like:
ldtk.draw_level(ldtk_project.levels[1], camera)