Struggling to get started with tilemaps

I'm trying to program a basic Zelda 1 style game and want to use the tilemap functions to handle the map layout in the play area. The following doesn't cause any errors but also isn't drawing the tilemap. I'm wondering if the issue is I'm not handling the data on the tile layout correctly, but I can't find a basic example of the code to use.

local bgtileset = gfx.imagetable.new("Images/bgtileset")

local bgtilemap = gfx.tilemap.new()
bgtilemap:setImageTable(bgtileset)
bgtilemap:setSize(25,11)
bgtilemap:setTiles({1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, 25)
bgtilemap:draw(0,64)

There's nothing wrong with your code. Just make sure that bgtilemap:draw(0, 64) is inside the playdate.update() function.

I just tried it but it still doesn't work. I also tried adding bgtileset:drawImage(1,0,64) to see if I could draw something directly from the tileset but that doesn't work either. However, when I look at the Lua memory in the simulator, the tileset is there and correctly showing as a table of 6 tiles. I don't understand.

Does this work for you?

test_tilemap.zip (9.2 KB)

test_tilemap

Yes, I tried replacing the image file with my own and it now looks like what I was attempting to do in the simulator. I guess I'll have to experiment and try to find out what else in the code is stopping it from working.

Thanks for your help!

1 Like