How to access TiledTilesetTile custom properties? #2673
Unanswered
max-vogler
asked this question in
Q&A
Replies: 1 comment 3 replies
-
Hi @max-vogler Unfortunately there are some co-mingling abstractions here that make this confusing. This part of the API is definitely not as friendly, the gid's are only part of Tiled's raw structure. I'll write an issue to make this better. Here is the code you can use to get at the tileset tile properties stashed on a tile const map: TiledMapResource = ...;
game.input.pointers.primary.on('down', evt => {
// ex TileMap data structure by name
const tilemap = map.getTileMapLayers().filter(tm => tm.name === 'Ground')[0];
const tile = tilemap.getTileByPoint(evt.worldPos);
const tileIndex = tilemap.tiles.indexOf(tile); // both ex and tiled share the same index
// Tiled data
// gid can be found by looking up the original data, locate layer by name
const tiledLayer = map.data.getTileLayerByName('Ground');
const tileGid = tiledLayer.data[tileIndex];
// Tiled tileset properties
const tiledTileset = map.getTilesetForTile(tileGid);
// odd quirk of Tiled's data the gid's here are off by 1 from the data array :/
const tiledTile = tiledTileset.tiles.find(t => t.id === (tileGid - 1));
console.log('gid', tileGid);
console.log('tile props', tiledTile?.properties);
}); In this example "custom prop 2" set to An alternative?You can use Tiled objects to store data around the Tiled map, which currently has a much smoother API. In this example we store the "player start" point and the "Camera" point. const excalibur = map.data.getExcaliburObjects();
if (excalibur.length > 0) {
const start = excalibur[0].getObjectByName('player-start');
if (start) {
player.pos.x = start.x;
player.pos.y = start.y;
console.log("player start", start.x, start.y);
console.log("props:" , start.getProperty<number>("Custom Prop"));
}
} QuestionWhat are planning to do in your game? We can prioritize make common uses cases better! |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using a Tiled tileset with custom properties on tiles, e.g. how a player can interact with the tile. I'm able to locate the tile that the player clicked on, but unsure how to get the associated custom properties:
Beta Was this translation helpful? Give feedback.
All reactions