Skip to content

Place tile objects on isometric maps where Tiled draws them - #1759

Merged
obiot merged 2 commits into
melonjs:masterfrom
vtxe02023274:fix/isometric-object-position
Oct 22, 2026
Merged

obiot merged 2 commits into
melonjs:masterfrom
vtxe02023274:fix/isometric-object-position

Conversation

@vtxe02023274

Copy link
Copy Markdown
Contributor

Description

Tile objects on isometric maps don't end up where Tiled draws them. TMXIsometricRenderer.adjustPosition had two problems:

  • it divided obj.x by half the tile width and obj.y by the tile height. Tiled stores isometric object positions in tile-height units on both axes (IsometricRenderer::pixelToScreenCoords), so this only matched 2:1 tiles
  • it used the projected point as the top left of the object, while Tiled aligns tile objects on isometric maps to their bottom center. The orthogonal adjustPosition already does y -= height, the isometric one overrides it without doing either

Now both coordinates are divided by tileheight, and objects with a gid are moved left by half their width and up by their height.

I compared against Tiled itself: rendered the same maps with Tiled's tmxrasterizer and with melonJS in Chromium, and compared the object pixels.

map before after
4x4, 186x108 tiles, five 40x40 / 30x60 tile objects 15200 px differ 80 px (one object at x = 690.6, rounding)
4x4, 64x32 tiles, bottom centers of four tile objects all off by (+w/2, +h) all match

Added two tests to tmxrenderer.spec.js with the values Tiled produces for the 186x108 map, both fail before this change. Changelog entry added under a new _unreleased_ heading.

Separate from this PR: TMXObject.setTile replaces the object's width/height with the tileset's tile size for non-collection tilesets, so a tile object resized in Tiled is drawn at the tile's own size (on every orientation). In the 64x32 map above the 16x16 objects are drawn 40x40 because of that. Happy to look at it separately if you want it fixed.

Type of change

  • Bug fix
  • New feature
  • Documentation update
  • Performance improvement
  • Refactoring (no functional changes)

Checklist

  • I have read the Contributing Guide
  • My code follows the existing code style (eslint and biome pass on the changed files)
  • I have tested my changes locally (pnpm test: 8164 passed, 2 failed — text-gradient.spec.js fails on master too, drawmesh_bench.spec.js timed out once under load on my machine)
  • I have added tests that cover my changes (if applicable)
  • The build succeeds (scripts/build.js)

Related issues

None that I found.

adjustPosition converted x with half the tile width instead of the tile height, which only matches 2:1 tiles, and used the projected point as the top left of tile objects instead of their bottom center.
@obiot

obiot commented Oct 21, 2026

Copy link
Copy Markdown
Member

thank you so much, excellent finding ! merging this one into 20.11, and I'll look at the setTile issue you found as well 👍

Moves the changelog entry under 20.11.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SeWCkETjW35ZbXDRswV1hx
@obiot
obiot merged commit 5f037e0 into melonjs:master Oct 22, 2026
3 checks passed
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