Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(tilemap): tile objects honor the diagonal flip

yhh605f1df00a7b
diff --git a/desktop/package.json b/desktop/package.json
index 396458e33..0220b23f8 100644
--- a/desktop/package.json
+++ b/desktop/package.json
@@ -34,7 +34,7 @@
"verify:render:tilemap": "vite build && ESTELLA_VERIFY_SCENE=/scenes/tilemap-flip.esscene ESTELLA_VERIFY_MANIFEST=/scenes/tilemap-flip.textures.json ESTELLA_VERIFY_W=256 ESTELLA_VERIFY_H=256 ESTELLA_VERIFY_STEPS=2 ESTELLA_VERIFY_EXPECT=\"[{\\\"x\\\":0.40,\\\"y\\\":0.36,\\\"rgb\\\":[255,0,0]},{\\\"x\\\":0.60,\\\"y\\\":0.36,\\\"rgb\\\":[0,255,0]},{\\\"x\\\":0.40,\\\"y\\\":0.58,\\\"rgb\\\":[0,0,255]},{\\\"x\\\":0.60,\\\"y\\\":0.58,\\\"rgb\\\":[255,255,0]}]\" electron scripts/headless-verify.mjs",
"verify:render:tilemap:transform": "vite build && ESTELLA_VERIFY_SCENE=/scenes/tilemap-transform.esscene ESTELLA_VERIFY_MANIFEST=/scenes/tilemap-transform.textures.json ESTELLA_VERIFY_W=256 ESTELLA_VERIFY_H=256 ESTELLA_VERIFY_STEPS=2 ESTELLA_VERIFY_EXPECT=\"[{\\\"x\\\":0.40,\\\"y\\\":0.36,\\\"rgb\\\":[255,255,0]},{\\\"x\\\":0.60,\\\"y\\\":0.36,\\\"rgb\\\":[0,255,0]},{\\\"x\\\":0.40,\\\"y\\\":0.58,\\\"rgb\\\":[0,0,255]},{\\\"x\\\":0.60,\\\"y\\\":0.58,\\\"rgb\\\":[255,0,0]}]\" electron scripts/headless-verify.mjs",
"verify:render:tilemap:multiset": "vite build && ESTELLA_VERIFY_SCENE=/scenes/tilemap-multiset.esscene ESTELLA_VERIFY_MANIFEST=/scenes/tilemap-multiset.textures.json ESTELLA_VERIFY_W=256 ESTELLA_VERIFY_H=256 ESTELLA_VERIFY_STEPS=6 ESTELLA_VERIFY_EXPECT=\"[{\\\"x\\\":0.40,\\\"y\\\":0.36,\\\"rgb\\\":[255,0,0]},{\\\"x\\\":0.60,\\\"y\\\":0.36,\\\"rgb\\\":[0,255,0]},{\\\"x\\\":0.40,\\\"y\\\":0.58,\\\"rgb\\\":[0,0,255]},{\\\"x\\\":0.60,\\\"y\\\":0.58,\\\"rgb\\\":[255,255,0]}]\" electron scripts/headless-verify.mjs",
- "verify:render:tilemap:gidobj": "vite build && ESTELLA_VERIFY_SCENE=/scenes/tilemap-gidobj.esscene ESTELLA_VERIFY_MANIFEST=/scenes/tilemap-gidobj.textures.json ESTELLA_VERIFY_W=256 ESTELLA_VERIFY_H=256 ESTELLA_VERIFY_STEPS=10 ESTELLA_VERIFY_EXPECT='[{\"x\":0.5,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":40},{\"x\":0.5,\"y\":0.12,\"rgb\":[0,0,0],\"tol\":30}]' electron scripts/headless-verify.mjs",
+ "verify:render:tilemap:gidobj": "vite build && ESTELLA_VERIFY_SCENE=/scenes/tilemap-gidobj.esscene ESTELLA_VERIFY_MANIFEST=/scenes/tilemap-gidobj.textures.json ESTELLA_VERIFY_W=256 ESTELLA_VERIFY_H=256 ESTELLA_VERIFY_STEPS=10 ESTELLA_VERIFY_EXPECT='[{\"x\":0.5,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":40},{\"x\":0.5,\"y\":0.12,\"rgb\":[0,0,0],\"tol\":30},{\"x\":0.8125,\"y\":0.375,\"rgb\":[0,0,255],\"tol\":40},{\"x\":0.9375,\"y\":0.375,\"rgb\":[255,255,0],\"tol\":40},{\"x\":0.875,\"y\":0.8125,\"rgb\":[0,0,255],\"tol\":40},{\"x\":0.875,\"y\":0.9375,\"rgb\":[255,255,0],\"tol\":40}]' electron scripts/headless-verify.mjs",
"verify:render:material": "vite build && ESTELLA_VERIFY_SCENE=/scenes/mat-tint.esscene ESTELLA_VERIFY_MANIFEST=/scenes/mat-tint.textures.json ESTELLA_VERIFY_W=256 ESTELLA_VERIFY_H=256 ESTELLA_VERIFY_STEPS=2 ESTELLA_VERIFY_EXPECT=\"[{\\\"x\\\":0.5,\\\"y\\\":0.5,\\\"rgb\\\":[255,0,0],\\\"tol\\\":40}]\" electron scripts/headless-verify.mjs",
"verify:render:ktx2": "vite build && ESTELLA_VERIFY_SCENE=/scenes/ktx2-sprite.esscene ESTELLA_VERIFY_MANIFEST=/scenes/ktx2-sprite.textures.json ESTELLA_VERIFY_W=256 ESTELLA_VERIFY_H=256 ESTELLA_VERIFY_STEPS=2 ESTELLA_VERIFY_EXPECT=\"[{\\\"x\\\":0.5,\\\"y\\\":0.5,\\\"rgb\\\":[0,180,0],\\\"tol\\\":50}]\" electron scripts/headless-verify.mjs",
"verify:render:cooked": "vite build && ESTELLA_COOK_FIXTURE=1 vitest run tests/cooked-verify-fixture.test.ts && electron scripts/headless-cooked-verify.mjs",
diff --git a/desktop/public/scenes/tilemap-gidobj/a.png b/desktop/public/scenes/tilemap-gidobj/a.png
index 3f9167c5d..b9603ce14 100644
Binary files a/desktop/public/scenes/tilemap-gidobj/a.png and b/desktop/public/scenes/tilemap-gidobj/a.png differ
diff --git a/desktop/public/scenes/tilemap-gidobj/map.tmj b/desktop/public/scenes/tilemap-gidobj/map.tmj
index 565663a34..f7b1ba7fb 100644
--- a/desktop/public/scenes/tilemap-gidobj/map.tmj
+++ b/desktop/public/scenes/tilemap-gidobj/map.tmj
@@ -14,7 +14,36 @@
"name": "Decor",
"visible": true,
"objects": [
- { "id": 1, "name": "greentile", "x": 0, "y": 16, "width": 16, "height": 16, "gid": 2, "rotation": 0 }
+ {
+ "id": 1,
+ "name": "greentile",
+ "x": 0,
+ "y": 16,
+ "width": 16,
+ "height": 16,
+ "gid": 2,
+ "rotation": 0
+ },
+ {
+ "id": 2,
+ "name": "split-plain",
+ "x": 16,
+ "y": 8,
+ "width": 8,
+ "height": 8,
+ "gid": 3,
+ "rotation": 0
+ },
+ {
+ "id": 3,
+ "name": "split-dflip",
+ "x": 16,
+ "y": 24,
+ "width": 8,
+ "height": 8,
+ "gid": 536870915,
+ "rotation": 0
+ }
]
}
],
@@ -23,12 +52,12 @@
"firstgid": 1,
"name": "a",
"image": "a.png",
- "imagewidth": 32,
+ "imagewidth": 64,
"imageheight": 16,
"tilewidth": 16,
"tileheight": 16,
- "columns": 2,
- "tilecount": 2
+ "columns": 4,
+ "tilecount": 4
}
]
}
diff --git a/sdk/src/tilemap/tilemapPlugin.ts b/sdk/src/tilemap/tilemapPlugin.ts
index 63a6563a2..5db16f86c 100644
--- a/sdk/src/tilemap/tilemapPlugin.ts
+++ b/sdk/src/tilemap/tilemapPlugin.ts
@@ -359,7 +359,12 @@ export class TilemapPlugin implements Plugin {
// in edit + play mode like the tile layers. Parented to the
// tilemap entity, so the sprite's local position is the object's
// offset within the map (pixels). H/V flip → flipX/flipY;
- // diagonal flip + rotation are follow-ups.
+ // diagonal (D) flip = transpose, decomposed as an extra 90° CW
+ // quad rotation with the flip axes exchanged (source H → display
+ // Y with the rotation's inversion baked in, source V → display X)
+ // and the sprite size swapped so the rotated quad fills the
+ // object's authored width×height box (whose centre is
+ // rotation-invariant). Pixel-verified against Tiled's rendering.
for (const group of cached.objectGroups ?? []) {
if (group.visible === false) continue;
for (const obj of group.objects) {
@@ -388,17 +393,20 @@ export class TilemapPlugin implements Plugin {
const rc = Math.cos(rad), rs = Math.sin(rad);
const px = obj.x + (w / 2) * rc - (-h / 2) * rs;
const py = -(obj.y + (w / 2) * rs + (-h / 2) * rc);
+ // The box centre above uses the authored rotation only;
+ // D adds content rotation on top of it.
+ const quadRad = dec.flipD ? rad + Math.PI / 2 : rad;
const tileChild = world.spawn(obj.name || `TileObject_${obj.id}`);
- world.insert(tileChild, Transform, rad !== 0
- ? { position: { x: px, y: py, z: 0 }, rotation: { w: Math.cos(-rad / 2), x: 0, y: 0, z: Math.sin(-rad / 2) } }
+ world.insert(tileChild, Transform, quadRad !== 0
+ ? { position: { x: px, y: py, z: 0 }, rotation: { w: Math.cos(-quadRad / 2), x: 0, y: 0, z: Math.sin(-quadRad / 2) } }
: { position: { x: px, y: py, z: 0 } });
world.insert(tileChild, Sprite, {
texture: ts.textureHandle,
- size: { x: w, y: h },
+ size: dec.flipD ? { x: h, y: w } : { x: w, y: h },
uvOffset: { x: col * uvW, y: 1 - (row + 1) * uvH },
uvScale: { x: uvW, y: uvH },
- flipX: dec.flipH,
- flipY: dec.flipV,
+ flipX: dec.flipD ? dec.flipV : dec.flipH,
+ flipY: dec.flipD ? !dec.flipH : dec.flipV,
layer: cached.layers.length,
});
world.insert(tileChild, RuntimeOnly, {});