Setting z-index for a tilemap?

Hi.
My game uses a tilemap to draw environment elements. Now I want to add something that should be drawn on top of everything on the screen (Message on the code) so I added this element as a sprite with a big z-index. This new element is drawn on top of every other sprite, but the tilemap is always drawn on top.
Is there a way to set the z-index for the tilemap so it respects the layer it should be drawn?

My code is extensive so I'll share snippets:
In scene init() method I set both the Message sprite and the tilemap

local tileset = gfx.imagetable.new("assets/images/tilemap-table-20-20.png")
    self.tilemap = gfx.tilemap.new()
    self.tilemap:setImageTable(tileset)
...
...
self.tilemap:setTiles(myLevel, 16)
    gfx.sprite.addWallSprites(self.tilemap, { 1, 2, 3, 4, 5 })

...
...
...
self.message = Message(200, 120)

And Message is a simple class extending from sprite

local pd <const> = playdate
local gfx <const>  = pd.graphics

Message = {}
class("Message").extends(gfx.sprite)

function Message:init(x, y)
    local messageBackground = gfx.image.new("assets/images/MessageBackground.png")
    self:setImage(messageBackground)
    self:moveTo(x, y)
    self:setZIndex(1000)
    self:add()
end

function Message:update()

end

and this is my scene:update() method

function scene:update()
    scene.super.update(self)

...
...

    self.tilemap:draw(0, 0)
end

Any idea on how to set the z-index for the tilemap so it draws below the Message?
Or any other method to get the same result?

Thanks in advance for your help.

Some extra info points.
I'm using Noble engine to handle scenes, but I'm using native sprites.

Answering myself after a little more digging...
Here is the solution: Timemap is above the player? - #5 by Mahekaru

So a code snippet of my new scene init()

local tileset = gfx.imagetable.new("assets/images/tilemap-table-20-20.png")
    self.tilemap = gfx.tilemap.new()
    self.tilemap:setImageTable(tileset)

...
self.tilemap:setTiles(myLevel, 16)
    gfx.sprite.addWallSprites(self.tilemap, { 1, 2, 3, 4, 5 })
    self.tileSprite = gfx.sprite.new()
    self.tileSprite:setTilemap(self.tilemap)
    self.tileSprite:setZIndex(0)
    self.tileSprite:setCenter(0, 0)
    self.tileSprite:moveTo(0, 0)
    self.tileSprite:add()

And just remove the tilemap:draw() call on the scene update method.

And now it works like a charm :smiley:

1 Like