Hello everyone,
I'm currently developing a game for the Playdate using Lua, and I'm facing an issue with the sprite draw()
function not being called.
Here is a brief description of the problem:
- I have a
Item
class that extendsgfx.sprite
. - The
Item:update()
function is being called repeatedly, and the coin's position is updating as expected. - However, the
Item:draw()
function is not being called, and therefore the blinking effect is not working.
I have tried the following solutions:
- Ensured that the
Item
sprite is added to the sprite system usingself:add()
. - Set
self:setVisible(true)
andself:setUpdatesEnabled(true)
. - Used
self:setIgnoresDrawOffset(true)
to ensure that the draw function is called even if the sprite is off-screen. - Added debug messages inside the
draw()
function to check if it is being called, but no messages are appearing.
Here is a snippet of my Item
class for reference:
lua
class('Item').extends(gfx.sprite)
function Item:init(game, x, y, itemType, groundY)
Item.super.init(self)
-- Initialization code...
-- Set the image
self.image = self.imageTable:getImage(1)
self:setImage(self.image)
-- Configure the sprite
self:setSize(imageWidth, imageHeight)
self:setCenter(0.5, 0.5)
self:setZIndex(50)
self:setUpdatesEnabled(true)
self:setVisible(true)
self:setIgnoresDrawOffset(true)
self:add()
print("Item:init - Added to sprite system")
end
function Item:draw()
print("Item:draw() called at position:", self.x, self.y)
self.image:draw(0, 0)
end
I would greatly appreciate any advice or suggestions on how to resolve this issue. Thank you in advance for your help!
Best regards, [Jbuta]