Unexpected sprite Offset when flipped

While working on a platformer sample, I encountered a really strange issue with my sprite.


As you can see in this gif the sprite is sometimes flickering and changing rapidly position before going back to its expected position.

After digging around it seems this is related to sprite:setImageFlip(playdate.graphics.kImageFlippedX)

If I leave the sprite flipped horizontally all the time, it seems the sprite will be rendered with an unexpected offset. Slowing down the movement I noticed it happened when the position is a multiple of 32 pixels.


As you can see the collision box of the character is in the right place but the sprite is not rendered at the right position. If I do not force to always redraw the whole screen, I also have sprite ghosting because the dirty rects are not correct.

The two places to reproduce the issues easily:
platformer_bug_colli_1 platformer_bug_colli_2

Here is the project with the bug

Bug flipped sprite.zip (220.1 KB)

1 Like

This also shows the problem:

gfx = playdate.graphics
im = gfx.image.new(16,32,gfx.kColorBlack)

local x = 0

function playdate.update() 
	x += 1

Dumb boundary conditions!

aha, it only happens with images without transparency–that’s why no one caught this before. I had the code right in that case but the matching bit in the function for drawing a flipped row without a mask had a >= where it should have been >. Thanks for catching this!

It seems sometimes using the worst programmer art is useful :sweat_smile:

1 Like