Help understanding Sprite:draw with setDrawOffset

Hello everyone!

I'm trying to understand the following:

I see that in the documentation, the sprite's draw callback will be provided with a dirty rect (x, y, w, h). Where x and y are usually 0, 0 and w, and h are the size of the sprite. This makes sense to me since the whole sprite is being marked dirty and will be redrawn.

However, once you setDrawOffset the x and y coordinates shift over with the draw offset. This causes an image drawn within a sprite at x and y to shift over.

After looking through the forums, I found this thread: setDrawOffset and Sprite:draw that mentioned this behavior but there was no further discussion. Neither image:drawIgnoringOffset or sprite:setIgnoresDrawOffset help in this case.

I could work around this in many ways:

  • passing (0,0) to image:draw
  • using sprite:setImage() instead of implementing my own sprite:draw()

My main questions is:
Is the dirty rect passed to Sprite:draw supposed to shift over with draw offset?

I'm on Windows SDK 2.4.1.


Here's a small example of the described scenario:

local image ="assets/img")

local mySprite =
mySprite:moveTo(200, 120)
mySprite:setSize(32, 32)
mySprite:setCollideRect(0, 0, 32, 32)

function mySprite:draw(x, y, width, height)
	-- x and y here are 0,0 until the offset kicks in.
function playdate.update()

	if playdate.buttonIsPressed( playdate.kButtonRight ) then
		local nx = mySprite.x + 1
		mySprite:moveTo(nx, mySprite.y)

	if playdate.buttonJustPressed( playdate.kButtonA ) then
		mySprite:moveTo(200, 120)
	local xOffset = 0
	local yOffset = 0

	if mySprite.x > (250) then
		xOffset = mySprite.x * -1 + (250)
	end, yOffset)


I never figured out why the offset affected the dirty rect. I just chose to ignore the dirty rect, since it's not that important unless you have some really heavy drawing code. Not a great answer, but you can consider it an optimization to come back to if needed later. So yeah, draw from (0, 0) for now.

Yup that's what I'm thinking. The real problem is that the approach described above is used in this library GitHub - NobleRobot/NobleEngine: A li'l game engine for Playdate. to draw animations. So I'm wondering if there is a fix that needs to be put in place within the SDK or NobleEngine.