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(editor): converge .tmj point objects into queryable Marker entities

yhh26726e22410f
diff --git a/desktop/src/main.tsx b/desktop/src/main.tsx
index 1a1b5e675..b9a3b2503 100644
--- a/desktop/src/main.tsx
+++ b/desktop/src/main.tsx
@@ -147,6 +147,13 @@ if (new URLSearchParams(location.search).has('automation')) {
/** Paint tiles into a TilemapLayer SOURCE entity (one undo step) — for shot tests. */
paintTiles: (sourceId: number, edits: { x: number; y: number; tileId: number }[]) =>
SceneCommands.paintTiles(sourceId, edits),
+ /** All LIVE Marker entities (hand-placed model entities AND `.tmj`-derived RuntimeOnly
+ * children), each with its `type` + whether it's a model entity (`src != null`) or a
+ * derived projection (`src == null`) — verifies object-group → Marker convergence. */
+ liveMarkers: () => ViewportController.markerIds().map((rt) => {
+ const g = ViewportController.getMarkerGizmo(rt);
+ return { rt, type: g?.type ?? null, src: SceneModel.sourceFor(rt) ?? null };
+ }),
/** Probe a layer's resolved tile-collision overlay — the SAME pieces the viewport
* draws + Play spawns. Returns null if nothing resolves; else piece counts by kind.
* Verifies the collision-layer pipeline end-to-end (refs → palette model → outlines). */
diff --git a/desktop/src/panels/Viewport.tsx b/desktop/src/panels/Viewport.tsx
index 7d1660dfc..d9901979c 100644
--- a/desktop/src/panels/Viewport.tsx
+++ b/desktop/src/panels/Viewport.tsx
@@ -869,9 +869,13 @@ export function Viewport() {
// position (click to select), so spawn points / waypoints / triggers are visible without
// being selected. Same per-frame rAF + structural id set as the camera/light gizmos.
const markerRefs = useRef(new Map<number, HTMLDivElement | null>());
+ // Markers can be MODEL entities (hand-placed → structRev) OR RuntimeOnly children a
+ // Tilemap source derives from a `.tmj` point object (world-only → no structRev bump).
+ // markerIds() rescans the live world, so also re-run on dataRev to catch the derived
+ // set once the async source load + derive lands.
const markerIds = useMemo(
() => (engine.status === 'ready' ? ViewportController.markerIds() : []),
- [structRev, engine.status],
+ [structRev, dataRev, engine.status],
);
// Physics colliders aren't drawn by the renderer — outline each (box polygon /
// circle) as a gizmo so you can see/tune collider shapes without entering Play.
diff --git a/examples/tilemap-demo/assets/maps/level.tmj b/examples/tilemap-demo/assets/maps/level.tmj
index 73a1f7f7e..59e7b952a 100644
--- a/examples/tilemap-demo/assets/maps/level.tmj
+++ b/examples/tilemap-demo/assets/maps/level.tmj
@@ -10,8 +10,8 @@
"height": 18,
"tilewidth": 18,
"tileheight": 18,
- "nextlayerid": 5,
- "nextobjectid": 1,
+ "nextlayerid": 6,
+ "nextobjectid": 4,
"tilesets": [
{
"firstgid": 1,
@@ -2449,6 +2449,21 @@
0,
0
]
+ },
+ {
+ "draworder":"topdown",
+ "id":5,
+ "name":"spawns",
+ "objects":[
+ {"id":1,"name":"player-spawn","type":"spawn","point":true,"x":90,"y":150,"width":0,"height":0,"rotation":0,"visible":true,"properties":[]},
+ {"id":2,"name":"enemy-spawn","type":"enemy","point":true,"x":400,"y":110,"width":0,"height":0,"rotation":0,"visible":true,"properties":[]},
+ {"id":3,"name":"checkpoint","type":"checkpoint","point":true,"x":260,"y":250,"width":0,"height":0,"rotation":0,"visible":true,"properties":[]}
+ ],
+ "opacity":1,
+ "type":"objectgroup",
+ "visible":true,
+ "x":0,
+ "y":0
}
]
}
\ No newline at end of file
diff --git a/sdk/src/tilemap/tilemapPlugin.ts b/sdk/src/tilemap/tilemapPlugin.ts
index 1f656c17e..c2f240fdc 100644
--- a/sdk/src/tilemap/tilemapPlugin.ts
+++ b/sdk/src/tilemap/tilemapPlugin.ts
@@ -2,7 +2,7 @@
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
import type { App, Plugin } from '../app';
import type { ESEngineModule } from '../wasm';
-import { Transform, TilemapLayer, Sprite, Canvas, RuntimeOnly, type TilemapLayerData } from '../component';
+import { Transform, TilemapLayer, Sprite, Canvas, RuntimeOnly, Marker, type TilemapLayerData } from '../component';
import { Schedule } from '../system';
import type { SystemDef } from '../system';
import { initTilemapAPI, shutdownTilemapAPI, TilemapAPI } from './tilemapAPI';
@@ -512,7 +512,26 @@ export class TilemapPlugin implements Plugin {
for (const group of cached.objectGroups ?? []) {
if (group.visible === false) continue;
for (const obj of group.objects) {
- if (obj.gid === undefined || obj.visible === false) continue;
+ if (obj.visible === false) continue;
+ // Non-tile objects: a POINT converges to a real Marker entity
+ // (spawn point / waypoint), so imported and hand-authored
+ // markers share ONE `Query(Marker)` surface. World-only
+ // (re-derived from the .tmj each load, like the tile-object
+ // sprites), parented so its local position is the object's map
+ // offset (Tiled anchors the point at x,y, y-down; world Y up).
+ // Other shapes (rect/ellipse/polygon) stay collision-group
+ // colliders — not projected here.
+ if (obj.gid === undefined) {
+ if (obj.shape === 'point') {
+ const markerChild = world.spawn(obj.name || `Marker_${obj.id}`);
+ world.insert(markerChild, Transform, { position: { x: obj.x, y: -obj.y, z: 0 } });
+ world.insert(markerChild, Marker, { type: obj.type || '' });
+ world.insert(markerChild, RuntimeOnly, {});
+ world.setParent(markerChild, entity);
+ children.push(markerChild);
+ }
+ continue;
+ }
const dec = decodeTiledGid(obj.gid);
// Resolve the tileset by global id (largest firstId <= id).
let ts: (typeof cached.tilesets)[number] | undefined;