After lots of bugs and trying to find an answer, I finally kind of got LDtk level format to work with my game so I can have levels and collisions. The collisions work fine, but I still haven't gotten it to draw properly, I'm pretty sure its how I'm initializing it. Right now, just as a prototype, I'm forcing the setTiles info by writing it by hand. Using world in setTiles like so:
tilemap:setTiles(world,8)
throws an error, so maybe I'm just missing something obvious, or something, but I couldn't find much on this.
Here's my progress:
For those interested, here's the initialization code, any help would be appreciated.
import "CoreLibs/object"
import "CoreLibs/graphics"
import "CoreLibs/sprites"
import "CoreLibs/timer"
import "player"
local pd <const> = playdate
local gfx <const> = playdate.graphics
import '../toyboxes/toyboxes'
import "LDtk"
local world
local tilemap = gfx.tilemap:new()
local tilesheet = gfx.imagetable.new("Images/tiles")
local function game_initialize()
playerInstance = Player(100,100)
playerInstance:add()
LDtk.load( "MyWorld.ldtk" )
assert("MyWorld.ldtk", "myw dne")
world = LDtk.create_tilemap("Level_0")
assert(world, "does not exist")
demoinfo = {0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1}
tilemap:setImageTable(tilesheet)
tilemap:setTiles(demoinfo, 8) -- Assuming 32x32 tiles; adjust based on your setup
-- Add wall sprites using LDtk data
local emptyTileIDs = LDtk.get_empty_tileIDs("MyWorld", "Walls")
gfx.sprite.addWallSprites(world, emptyTileIDs)
print(world)
-- Set the tilemap data using the world loaded from LDtk
end
game_initialize()
function pd.update()
gfx.sprite.update()
pd.timer.updateTimers()
tilemap:draw(0,0)
end
Very slow process, but working on it.
Bouncy Block -