Hello everyone,
I have a sprite (black, white and transparent pixels) and want it do be drawn over any other objects in my scene. I tried setting the z-Index of my sprite, tried changing around draw statements for my different components but no luck. I am pretty new to Lua and the SDK but I couldn't find an answer to this yet.
More information:
The main sprite has an animation loop and looks something like this (shortened for clarity):
Sprite Code
import "CoreLibs/sprites"
local gfx = playdate.graphics
local geo = playdate.geometry
Cat = {}
Cat.__index = Cat
function Cat:new()
local catImageTable = gfx.imagetable.new("/images/catsprite-extended-table-32-32-2.png")
assert(catImageTable)
local self = gfx.sprite.new()
self:setZIndex(10000)
self:setScale(3)
self.getAlwaysRedraw()
self.loop = gfx.animation.loop.new(200, catImageTable, true)
self.loop.startFrame = 1
self.loop.endFrame = 4
function self:update()
self.x = self.x + self.dx
self.y = self.y + self.dy
self:moveTo(self.x, self.y)
end
function self:draw()
local newImage = self.loop:image()
newImage:setInverted()
assert(newImage)
gfx.setColor(gfx.kColorBlack)
self:setImage(newImage)
end
return self
end
The main sprite has a animation loop and looks something like this:
Main Code
import 'cat'
import "CoreLibs/sprites"
import "CoreLibs/graphics"
local gfx = playdate.graphics
local width = playdate.display.getWidth()
local height = playdate.display.getHeight()
catSprite = Cat:new()
catSprite:moveTo(100, height - 32 * 1.5)
catSprite:add()
function drawField()
local widthScoreA = scoreFont:getTextWidth(scoreA)
gfx.drawText(scoreA, width / 2 - 26 - widthScoreA, 10)
gfx.drawText(scoreB, width / 2 + 20, 10)
gfx.setColor(gfx.kColorWhite)
gfx.setLineWidth(4)
for i = 0, 8 do
gfx.drawLine(width / 2, i * 28, width / 2, i * 28 + 14)
end
end
function playdate.update()
gfx.sprite.update()
drawField()
catSprite:draw()
end
The sprite looks like this, the grey pixels are transparency because it's a screenshot:
I wasn't allowed to add more than one picture so I hope this I enough for now.
I am working with SDK in version 1.9.0 on my Mac with the simulator.
I bet I missed a lot of details so feel free to ask questions.