Load tilemaps created with LDtk in playdate games
You can add it to your Playdate project by installing toybox.py, going to your project folder in a Terminal window and typing:
toybox add LDtkImporter
toybox update
Then, if your code is in the source
folder, just import the following:
import '../toyboxes/toyboxes.lua'
You first need to copy the file Ldtk.lua
in your playdate project and to import it
import 'LDtk'
Next you need to load your main .ldtk file, typically during the game loading
LDtk.load( "MyWorld.ldtk" )
If your LDtk world is saved in multiple files (in this case you see a .ldtkl file for each level in your structure) you need to manually load the levels.
LDtk.load_level( "TheFirstLevel" )
And you can also release the level and the assets used by it.
LDtk.release_level( "TheFirstLevel" )
It is usually better to load a new level before releasing the previous one because if they share the same asset, these assets will not need to be loaded.
When you want to finally use a level in your game, you need to create the playdate tilemap object
LDtk.create_tilemap( "TheFirstLevel" )
You can also query the tiles using enum values you have setup in your Ldtk world using LDtk.get_tileIDs()
but to generate collision the Playdate SDK requires tiles that are should by empty so `LDtk.get_empty_tileIDs() should be used instead.
local tilemap = LDtk.create_tilemap( "TheFirstLevel", "gameplay_layer" )
playdate.graphics.sprite.addWallSprites( tilemap, LDtk.get_empty_tileIDs( "TheFirstLevel", "Solid", "gameplay_layer") )
LDtk.get_entities()
will give you all the entities setup in a level including all their custom fields.
for index, entity in ipairs( LDtk.get_entities( "TheFirstLevel" ) ) do
if entity.name=="Player" then
player.sprite:add()
player.init( entity )
end
end
- Fix bug introduced in 1.06 where tileset would not load + code cleanup (Thank SquidGoDev)
- add property world_positon to entities (LDtk version 1.5.0)
- add new neighbours option (back, front, northwest, northeast, southwest, southeast) (Thx jojomo96)
- Improve error reporting
- Added MIT License to the project
- Add new function to get the level name from IID (Thx GammaGames)
- Fix path bug when exporting level (Thx zukas3)
- Fix loading of custom data (Thx GammaGames)
- Fix issue with fast loading that was not using the correct path
- Add error message when the level lua file is not found when using fast loading
- Fix crash when the LDtk internal icons are used in a level
- Make it possible to have the ldtk file at the root of the project
- Make it possible to use tileset that are in any folder of the project, not just under the ldtk file
- Added function to generate image from a tileset rect