My understanding based on some other posts and documentation is that I could render a nineslice at or immediately after the background (via setBackgroundDrawingCallback callback: Inside Playdate) but I'm unsure how to interlace between sprites of varying Z order - if nineslice exposed an image I could set a sprite to it to manage the ordering, but it doesn't look like the api exposes this, and there are only direct rendering calls for a nineslice
It actually works the other way around. You can’t set a sprite for a nineslice but you can draw the nineslice on an existing sprite’s image. It would look something like this:
Ace thanks RDK, this did exactly what I needed, code sample:
spriteA = spritelib.new()
spriteA:setImage(gfx.image.new("images/dummy"))
spriteA:moveTo(50, 50)
spriteA:addSprite()
spriteNS = spritelib.new() -- This represents the nineslice sprite, set size to match
spriteNS:setImage(gfx.image.new(100,60, gfx.kColorWhite))
spriteNS:moveTo(70, 70)
spriteNS:addSprite()
spriteB = spritelib.new()
spriteB:setImage(gfx.image.new("images/dummyg"))
spriteB:moveTo(100, 80)
spriteB:addSprite()
-- Nineslice
local ns = gfx.nineSlice.new("images/nineslice", 5, 5, 5, 3)
assert(ns)
-- Set nineslice sprite in the middle via z order
spriteA:setZIndex(1)
spriteNS:setZIndex(2)
spriteB:setZIndex(3)
function playdate.update()
spritelib.update()
-- use lock focus to overwrite the spriteNS image with the nineslice draw
gfx.lockFocus(spriteNS:getImage())
ns:drawInRect(0, 0, 100, 60)
gfx.unlockFocus()
end