I’m trying to get information from objects in a Tiled map but I can’t find how. TCastleTiledMapData exposes only the tiles data through TCastleTiledapData.TileRenderData () (which isn’t documented, by the way) but the editor renders the objects, so it contains the data and is accessible. But how?
In general, the answer depends on the exact information you need.
-
There’s more information in
TCastleTiledMapData– see API docs of TCastleTiledMapData -
The TileRenderData method is documented, although I admit this is spartan documentation:) I want to eventually have friendlier API and more documented API to access it all. For now, you have to explore
TCastleTiledMapData, it mostly follows Tiled data arrangement. -
The simple example is in strategy_game_demo, see https://github.com/castle-engine/castle-engine/blob/64d06f639c6c3cfd09e49ec2deb459e17ea590dd/examples/tiled/strategy_game_demo/code/gameunit.pas#L162 :
function TUnitsOnMap.IsWater(const TilePosition: TVector2Integer): Boolean;
var
Tileset: TCastleTiledMapData.TTileset;
Frame: Integer;
HorizontalFlip, VerticalFlip, DiagonalFlip: Boolean;
begin
Result := Map.Data.TileRenderData(TilePosition,
Map.Data.Layers[0],
Tileset, Frame, HorizontalFlip, VerticalFlip, DiagonalFlip) and
{ Water is on 1, 5, 9 tiles (counting from 0) in data/maps/tileset-terrain.png . }
((Frame mod 4) = 1);
end;
Let me know which exactly information you’re looking for, I can help there more:)
I know I can get information from tile layers, but I need information from object layers (points, rectangles, polygons, ellipses, etc.). For example: I’m using points to mark the player and enemy spawn places and polygons to define the paths. But I can’t find how I can retrieve this information. I need to check their name and type (to know what it defines) and retrieve the information (coordinates, vectors…) to use it in the game.