I have to draw tile map tiles before I add wall sprites. This seems odd.
This code displays the sprites correctly:
local pd <const> = playdate
local gfx <const> = pd.graphics
local imagetable, error = gfx.imagetable.new("Tilemap/walls")
assert(imagetable, error)
local wallsTilemap <const> = gfx.tilemap.new()
wallsTilemap:setImageTable(imagetable)
local tiles = {
1, 2, 3,
4, 0, 6,
7, 8, 9
}
wallsTilemap:setTiles(tiles, 3)
wallsTilemap:draw(0,0)
local collisionSprites = gfx.sprite.addWallSprites(wallsTilemap, {0})
for i = 1, #collisionSprites do
gfx.sprite.addSprite(collisionSprites[i])
end
Moving wallsTilemap:draw(0,0)
after the gfx.sprite.addWallSprites
line causes the sprites not to display though.
local pd <const> = playdate
local gfx <const> = pd.graphics
local imagetable, error = gfx.imagetable.new("Tilemap/walls")
assert(imagetable, error)
local wallsTilemap <const> = gfx.tilemap.new()
wallsTilemap:setImageTable(imagetable)
local tiles = {
1, 2, 3,
4, 0, 6,
7, 8, 9
}
wallsTilemap:setTiles(tiles, 3)
local collisionSprites = gfx.sprite.addWallSprites(wallsTilemap, {0})
wallsTilemap:draw(0,0) -- <= I've just moved this line.
for i = 1, #collisionSprites do
gfx.sprite.addSprite(collisionSprites[i])
end