Skip to content

Tiled: draw tile objects and collection tiles where Tiled draws them - #1760

Merged
obiot merged 1 commit into
masterfrom
fix/tile-object-size-alignment
Oct 22, 2026
Merged

obiot merged 1 commit into
masterfrom
fix/tile-object-size-alignment

Conversation

@obiot

@obiot obiot commented Oct 22, 2026

Copy link
Copy Markdown
Member

Follow-up to #1759. Six Tiled fixes, every one checked against Tiled's own renderer (tmxrasterizer, Tiled 1.12.1) rather than against numbers worked out by hand.

Fixes

  • Resized tile objects: an object resized in Tiled keeps its size, its tile stretched to fill it, and collides at that size. From a tileset image it was drawn and collided at the tile's size (reported in Place tile objects on isometric maps where Tiled draws them #1759).
  • objectalignment: tile objects are placed by their tileset's object alignment. They were always anchored at the bottom left, or the bottom center on isometric maps.
  • Image-collection tile objects, resized or flipped: drawn on their box. Their sprite kept a centered anchor (the rotation branch ran for a rotation of 0), so the scale and flip, applied about the top left, pushed a resized one up and left and a flipped one a whole width to the right.
  • Rotated tile objects: turn about their alignment point, as in Tiled, sprite and body alike. They turned about their top left (a centered anchor for collections). alignTileObject moves the top left by a - R·a, so neither transform changes.
  • Animated tile objects: load and play. From a tileset image, addAnimation refused the string frame names (string parameters for addAnimation are not allowed for standard spritesheet based Texture); frames are now named by position. An image collection had no texture (TypeError); TMXTileset#getAnimationTexture() builds one canvas atlas holding its animation frames.
  • Tile layers, image collections of mixed heights: each tile sits on the bottom of its cell. With tilerendersize="tile" every tile was placed as if it were as tall as the tallest image. Collections always use the CPU path, so the fix covers every renderer.

All of these are released behaviour except the objectalignment support, which is new.

Verification

  • Against Tiled's render: 16 maps (orthogonal, isometric 2:1 and 64x40, Kenney's isometric landscape art as an image collection, rotated, animated, flipped layers) rendered by tmxrasterizer and by melonJS on the same TMX, then pixel-diffed. Non-rotated objects and every tile layer match pixel for pixel; master differs on roughly every drawn pixel and fails to load both animated maps. Animation frame 1 matches Tiled advanced past frame 0.
  • Geometry: melonJS's own transform (pos + currentTransform) puts 125 points on 19 objects within 5.6e-6 px of Tiled's placement rules. Rendered rotated objects land within 0.51 px with subPixel on (Tiled's own render is within 0.37 px of the rules); the remaining edge differences are the two rasterizers sampling a rotated image.
  • Tests: new specs in tmxtilemap.spec.js and tmxrenderer.spec.js; 18 mutations (each fix reverted on its own) all fail at least one test. Full suite 8,211 passed, 10 skipped; lint and build clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SeWCkETjW35ZbXDRswV1hx

Checked against Tiled's own renderer (tmxrasterizer) on orthogonal and
isometric maps, including a map built from Kenney's isometric tiles:

- a tile object resized in Tiled keeps its size and its tile is
  stretched to fill it; it was drawn and collided at the tile's size
- tile objects follow their tileset's objectalignment; they were always
  anchored at the bottom left (bottom center on isometric maps)
- a resized or flipped tile object from an image collection is drawn on
  its box; its sprite kept a centered anchor that the scale and flip,
  applied about the top left, pushed off it
- a rotated tile object turns about its alignment point, sprite and
  body alike; it turned about another point
- animated tile objects load and play: a tileset image refused the
  string frame names, and an image collection had no texture (it now
  gets one canvas atlas holding its animation frames)
- in a tile layer, collection tiles of different heights each sit on
  the bottom of their cell instead of being placed as tall as the
  tallest image

Non-rotated objects and tile layers match Tiled's render pixel for
pixel; melonJS's transforms match Tiled's placement rules to float
precision. Every new test fails with its fix reverted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SeWCkETjW35ZbXDRswV1hx
Copilot AI balanced review requested due to automatic review settings October 22, 2026 05:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@obiot
obiot merged commit 2a80f9d into master Oct 22, 2026
6 checks passed
@obiot
obiot deleted the fix/tile-object-size-alignment branch October 22, 2026 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants