Visual glitch going behind another sprote

On the game I'm making, I've been using a tilemap set to an imagetable set to a sprite to generate my world in this way:

self.tm = gfx.tilemap.new()
self.tm:setImageTable(self.tilesheet)
self.tm:setTiles(self.tiles, self.worldTileWidth)
	
self.bg = gfx.sprite.new(self.tm)
self.bg:setCenter(0, 0)
self.bg:add()

I'm now trying to do the same to create a foreground layer. Treetops, building roofs, etc. Using the exact same code as the above, but to set a different tilesheet to a foreground sprite with a different Z index.

But now I'm getting some weird drawing glitches where the player sprite image sort of drags behind its real location. Here's a gif with collision boxes and screen updates turns on:

gif

This seems to only happen if the player sprite is fully behind the roof or overlapping from the top. If the feet stick out the bottom, then it doesn't seem to happen. It also doesn't happen with the treetops that are part of the same sprite. Finally, if I shift the rooftops Zindex to be behind the player, it draws properly.

Any thoughts?

I think this is another instance of Using transparent images as tiles on tilemap lead to smearing effect - #6 by QuinnStephens (link to workaround)

ah yeah that must be it. Thank you!

Annoyingly, I'm using tiles that have some transparent pixels, tiles that are completely transparent, so I will need to figure out how to apply the workaround to that.

Or I can simply redesign the building so the roof takes up full tiles and doesn't need transparent pixels at all...

Thanks again!