I’m using MGE to import tiled maps and everything is working great, except I can’t figure out how to get position data from the objects layer in tiled. Is there any additional documentation for how to access that data?
For reference, when a level loads I want it to parse out the tiles and then place objects at points in the map based on the name/type of the object in tiled, so I need to access the position of the object, the name, and the type
Any suggestions?
Sorry for all the questions but this has been the best resource for me in these minor hurdles so thanks so much!
Each TiledMapObjectLayer has the following property: public TiledMapObject[] Objects { get; }
With that, you can go through the array and obtain the Name, Type, and Position of those objects.
1 Like
Maybe this is a stupid question, but how do I load the map into the tiledmapobject array? is it similar to using Load.Content to load the map into the tiled map?
If you loaded the map through Content.Load already, you should have a reference to the TiledMap object. From there you can find all object layers through the public ReadOnlyCollection<TiledMapObjectLayer> ObjectLayers { get; }
property or use public T GetLayer<T>(string layerName) where T : TiledMapLayer;
with TiledMapObjectLayer to retrieve the layer you want.
As an example, I have a Tiled map with a dedicated collision layer. I have this property in a wrapper class:
public TiledMapObjectLayer CollisionLayer { get; private set; } = null;
To retrieve my collision layer, I simply do this: CollisionLayer = Map.GetLayer<TiledMapObjectLayer>(LevelGlobals.CollisionLayerName);
From there I have access to all the objects in the collision layer.
1 Like
That is exactly what I needed!!! thank you so much!!