Tilemap behaves unexpectedly when drawOffset is set

When drawing tilemap with a sourceRect and drawOffset, it behaves differently from how a simple image is drawn. I built a minimal example that shows this: minimal-example.zip (17.4 KB)

The loop shows how drawOffset and sourceRect work in isolation and together. I would expect that the third part would combine effects of both, but that happens only in case of the image.

-- the third part of the loop combines non-zero drawOffset 
-- and non-zero sourceRect origin
gfx.setDrawOffset(x, y)
map:draw(10, 10, x, y, 200, 200)
pic:draw(230, 50, gfx.kImageUnflipped, x, y, 100, 100)

The result in action (the problem occurs when the counter in top right is in between 200 and 299):

offsets-comp-img

The tilemap cancels both steps out, probably because drawOffset is applied both onto the tilemap and its tiles in some way. (When I set a different value for offset and drawRect origin, it’s visible that both offset and drawRect are applied.)

Credit: This behavior was discovered by @edzillion on Squad Discord, I was just trying to explain… and then debug :wink:

2 Likes

I thought that was the clip rect bug I mentioned here: Image:draw() in sprite:draw() callback with sourceRect draw at x*2,y*2 in v1.13.1 - #2 by dave but in your demo it looks like image:draw() with both offset and source rect is working correctly. I need to take another look at that one, double-check I didn't miss something there..

Okay, found it. We fixed that for images (Image:draw: drawOffset affects sourceRect instead of location - #3 by rols) but not for tilemaps. I've got the fix in, and I've also added tilemap:drawIgnoringOffset() to match image:drawIgnoringOffset() (which means it can jump the line a bit and get into the next API update instead of a more distant bugfix release :wink::shushing_face:)

2 Likes

Thanks, that’s great! :slight_smile: :man_bowing:

I wasn’t here for the first bug, so that did not occur to me :slight_smile: