Repository navigation
fix(tilemap): anchor tile objects at their bottom-left corner - #2
Merged
Merged
Conversation
Tiled anchors a tile object at its bottom-left corner, where a plain rectangle object is anchored top-left. The renderer passed the object position straight through as the top-left, so every tile object drew a full height below where the editor showed it, and the taller the object the more obvious the gap. Shift the draw position up by the drawn height, which follows the object's size rather than the tile's natural height so resized objects move by what the editor shows.
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Tiled anchors a tile object (an object with a
gid) at its bottom-left corner. A plainrectangle or ellipse object is anchored top-left.
drawObjectLayerpassed the object's positionstraight through as the top-left:
drawTileImage(*tileset, resolvedId, object.tile, object.position + offset, object.rotation, scale);So every tile object drew one full height below where the editor showed it. The error scales with
the object, so small decoration looks roughly right while anything large is plainly misplaced.
Seen in TinCan: a decoration object placed at y=5712 with a drawn height of 192 should render from
y=5520, and rendered from y=5712 — 192px low, sitting well below the ground tiles it was aligned to.
Fix
Shift the draw position up by the drawn height:
Using
sourceRect.h() * scale.yrather than the tile's natural height means a resized tile objectmoves by the height the editor actually shows.
Tests
Renderer: draws tile objects from object layers, skipping shapesasserted the old position, so itwas pinning the bug in place — it now expects y=-8 for a 16px tile placed at y=8.
Added
Renderer: a resized tile object is anchored at its scaled bottom-leftto cover the scaledcase, which needed a
scalefield on the mock'sDrawCall(the mock recorded position, pivot androtation but not scale).
Not covered here
Tiled also rotates a tile object about that same bottom-left anchor, while
drawTileImagepivotsabout the tile centre (
tile_map_renderer.cpp:72-75). A rotated tile object is still misplacedafter this change. That sits in the flip-flag composition and is left for its own change.
Downstream
Any map that was authored against the old behaviour — by nudging tile objects up to compensate —
will need those objects moved back.