setBackgroundDrawingCallback not redrawing when moving multiple overlapping sprites

Platform: Windows
SDK: 1.11.1
Repro: Simulator and Device

I believe there's possibly a bug with the background not refreshing properly when moving multiple Sprites at once that partially overlap. In the video below, the piece is actually made up of 3 Sprites, and the background grid is drawn using setBackgroundDrawingCallback.

This "ghosting" only started happening when I added a short "bounce" animation after moving the piece, I think because when moving left, the Sprites will partially overlap for just a few frames. Without the bounce animation, this bug doesn't happen. It also doesn't happen when moving right, I think because the sprites are sorted R to L, so there is no partial overlap when moving that direction.

Apologies as this is hard to describe.

Expected behavior: Ghosting does not happen when moving pieces with the bounce animation.


Some code for the "nudge":

	self.nudgeTimer =, 0, 1, easings.inOutCubic)
    self.nudgeTimer.updateCallback = function()
		for _, tile in pairs(self.tiles) do
			tile.sprite:moveTo(tile.sprite.x - (pixelsPerFrame * cols), tile.sprite.y - (pixelsPerFrame * rows))

And nothing fancy for the BG:

	function(x, y, width, height)
		-- Only draw the dirty part of the screen
		gfx.setClipRect(x, y, width, height)
        -- ... draw grid here ...
		-- Reset when finished drawing

Could this be a dirty issue?

What does the Simulator "show screen updates" look like?

If you mark the whole screen dirty as a test does this go away?

Sorry for so many questions.

Forcing the BG dirty does fix it, but trying to avoid that.

The sim shows the screen redrawing around just the piece tiles as it moves (will try to record a gif later, heading out for now).

1 Like

If BG dirty fixes it, then it's either a case of setting small dirty rects during your bounce, or perhaps a bug if that is not automatically being set when it should be. Depends on your code.

Oh you know what, after testing briefly on SDK 1.12.0 (Simulator only so far) I think this is fixed!

EDIT: Confirmed on device, so far so good. My guess would be an edge case with the dirty rects/background not redrawing properly in the case where multiple Sprites moved (with partial overlap) at the same time.


There was a bug where a sprite that overlaps two separate dirty rects would get the wrong "drawn bounds" rect (the area of the screen that it's drawn on) leading to cases where it would leave gunk behind. Sounds like that's what was happening here. :sweat_smile:

1 Like

Thanks Dave, sounds exactly like what I ran into. :slight_smile: