Hello there,
I was using playdate.graphics.sprite.setBackgroundDrawingCallback to setup a function which will automatically render the background image of my game (like one of the examples does).
At some point the game transitions to another mode, where I don't want or need that background image callback anymore.
So I called
playdate.graphics.sprite.setBackgroundDrawingCallback(nil)
to clear the callback.
This seemed to work for a while, however when I now added another state afterwards, which again uses the background drawing callback, I ran into errors:
Note: this is after I already called setBackgroundDrawingCallback with a valid function to set it again.
So essentially this does not work:
local backgroundDraw = function ( x, y, width, height )
-- draw call or whatever
end
playdate.graphics.sprite.setBackgroundDrawingCallback(backgroundDraw)
playdate.graphics.sprite.update()
-- insert game logic here
playdate.graphics.sprite.setBackgroundDrawingCallback(nil)
-- more game logic (without rendering a background image)
playdate.graphics.sprite.setBackgroundDrawingCallback(backgroundDraw)
playdate.graphics.sprite.update() -- this will now crash
Apparently once set to nil, the drawCallback cannot be set properly anymore afterwards.
One has to do the following instead:
playdate.graphics.sprite.setBackgroundDrawingCallback(function(x,y,width,height) end)
Maybe this can be mentioned in the documentation at least, if it is not a bug.
Small test project attached to reproduce the issue:
playdate-test.zip (20.8 KB)
Kind regards.