Class TiledExtensions
A set of extensions for dealing with MonoGame.Extended tiled maps
public static class TiledExtensions
- Inheritance
-
TiledExtensions
- Inherited Members
Methods
Get(TiledMapProperties, string)
Gets the property with the given key, or null if there is none.
public static string Get(this TiledMapProperties properties, string key)
Parameters
propertiesTiledMapPropertiesThe set of properties
keystringThe key by which to get a property
Returns
- string
The property, or null if there is none
GetArea(TiledMapObject, TiledMap, Vector2?, TiledMapTileFlipFlags)
Returns the area that a tiled map object covers. The area returned is in percent, meaning that an area that covers a full tile has a size of 1,1.
public static RectangleF GetArea(this TiledMapObject obj, TiledMap map, Vector2? position = null, TiledMapTileFlipFlags flipFlags = TiledMapTileFlipFlags.None)
Parameters
objTiledMapObjectThe object whose area to get
mapTiledMapThe map
positionVector2?The position to add to the object's position
flipFlagsTiledMapTileFlipFlagsThe flipping of the tile that this object belongs to. If set, the returned area will be "flipped" in the tile's space so that it matches the flip flags.
Returns
- RectangleF
The area that the tile covers
GetBool(TiledMapProperties, string)
Gets a boolean property with the given key, or null if there is none.
public static bool GetBool(this TiledMapProperties properties, string key)
Parameters
propertiesTiledMapPropertiesThe set of properties
keystringThe key by which to get a property
Returns
- bool
The boolean property, or false if there is none
GetColor(TiledMapProperties, string)
Gets a Color property with the given key, or null if there is none.
public static Color GetColor(this TiledMapProperties properties, string key)
Parameters
propertiesTiledMapPropertiesThe set of properties
keystringThe key by which to get a property
Returns
- Color
The color property
GetFloat(TiledMapProperties, string)
Gets a float property with the given key, or null if there is none.
public static float GetFloat(this TiledMapProperties properties, string key)
Parameters
propertiesTiledMapPropertiesThe set of properties
keystringThe key by which to get a property
Returns
- float
The float property, or 0 if there is none
GetGlobalIdentifier(TiledMapTilesetTile, TiledMapTileset, TiledMap)
Gets the global tile identifier for the given tiled map tileset tile. The global tile identifier is the identifier within all of the tile sets that the map has.
public static int GetGlobalIdentifier(this TiledMapTilesetTile tile, TiledMapTileset tileset, TiledMap map)
Parameters
tileTiledMapTilesetTileThe tile whose global identifier to get
tilesetTiledMapTilesetThe tileset the tile is from
mapTiledMapThe map the tile is on
Returns
- int
The global identifier
GetInt(TiledMapProperties, string)
Gets an int property with the given key, or null if there is none.
public static int GetInt(this TiledMapProperties properties, string key)
Parameters
propertiesTiledMapPropertiesThe set of properties
keystringThe key by which to get a property
Returns
- int
The int property, or 0 if there is none
GetLocalIdentifier(TiledMapTile, TiledMapTileset, TiledMap)
Gets the local tile identifier for the given tiled map tile. The local tile identifier is the identifier within the tile's tileset.
public static int GetLocalIdentifier(this TiledMapTile tile, TiledMapTileset tileset, TiledMap map)
Parameters
tileTiledMapTileThe tile whose identifier to get
tilesetTiledMapTilesetThe tileset the tile is from
mapTiledMapThe map the tile is on
Returns
- int
The local identifier
GetObjects(TiledMap, string, bool, bool)
Returns all of the objects by the given name, or by the given type, on the given map.
public static IEnumerable<TiledMapObject> GetObjects(this TiledMap map, string id, bool searchName = true, bool searchType = false)
Parameters
mapTiledMapThe layer whose objects to search
idstringThe name or type name of the objects to find
searchNameboolWhether to search object names
searchTypeboolWhether to search object types
Returns
- IEnumerable<TiledMapObject>
An enumerable of tiled map objects that match the search
GetObjects(TiledMapObjectLayer, string, bool, bool)
Returns all of the objects by the given name, or by the given type, in an object layer.
public static IEnumerable<TiledMapObject> GetObjects(this TiledMapObjectLayer layer, string id, bool searchName = true, bool searchType = false)
Parameters
layerTiledMapObjectLayerThe layer whose objects to search
idstringThe name or type name of the objects to find
searchNameboolWhether to search object names
searchTypeboolWhether to search object types
Returns
- IEnumerable<TiledMapObject>
An enumerable of tiled map objects that match the search
GetSpriteEffects(TiledMapTile)
Converts a tile's flip settings into Microsoft.Xna.Framework.Graphics.SpriteEffects.
public static SpriteEffects GetSpriteEffects(this TiledMapTile tile)
Parameters
tileTiledMapTileThe tile whose flip settings to convert
Returns
- SpriteEffects
The tile's flip settings as sprite effects
GetTextureRegion(TiledMapTileset, TiledMapTilesetTile)
Returns the texture region, as a rectangle, that the given tile uses for rendering.
public static Rectangle GetTextureRegion(this TiledMapTileset tileset, TiledMapTilesetTile tile)
Parameters
tilesetTiledMapTilesetThe tileset the tile is on
tileTiledMapTilesetTileThe tile
Returns
- Rectangle
The tile's texture region, in pixels.
GetTile(TiledMap, LayerPosition)
Returns the tiled map tile at the given location on the layer with the given name.
public static TiledMapTile GetTile(this TiledMap map, LayerPosition pos)
Parameters
mapTiledMapThe map
posLayerPositionThe layer position to get the tile at
Returns
- TiledMapTile
The tile at the given location, or default if the layer does not exist
GetTile(TiledMap, string, int, int)
Returns the tiled map tile at the given location on the layer with the given name.
public static TiledMapTile GetTile(this TiledMap map, string layerName, int x, int y)
Parameters
mapTiledMapThe map
layerNamestringThe name of the layer the tile is on
xintThe x coordinate of the tile
yintThe y coordinate of the tile
Returns
- TiledMapTile
The tile at the given location, or default if the layer does not exist
GetTile(TiledMapTileLayer, int, int)
Returns the tiled map at the given location on the given layer
public static TiledMapTile GetTile(this TiledMapTileLayer layer, int x, int y)
Parameters
layerTiledMapTileLayerThe layer to get the tile from
xintThe tile's x coordinate
yintThe tile's y coordinate
Returns
- TiledMapTile
The tiled map tile at the location, or default if the location is out of bounds
GetTileLayerIndex(TiledMap, string)
Gets the layer index of the layer with the given name in the MonoGame.Extended.Tiled.TiledMap.Layers array.
public static int GetTileLayerIndex(this TiledMap map, string layerName)
Parameters
mapTiledMapThe map
layerNamestringThe name of the layer
Returns
- int
The resulting index
GetTileSize(TiledMap)
Returns the width and height of a tile on the given map, as a vector.
public static Vector2 GetTileSize(this TiledMap map)
Parameters
mapTiledMapThe map
Returns
- Vector2
The width and height of a tile
GetTiles(TiledMap, int, int)
For an x and y coordinate, returns an enumerable of all of the tiles on each of the map's MonoGame.Extended.Tiled.TiledMap.TileLayers.
public static IEnumerable<TiledMapTile> GetTiles(this TiledMap map, int x, int y)
Parameters
Returns
- IEnumerable<TiledMapTile>
All of the tiles on the map at the given location
GetTileset(TiledMapTile, TiledMap)
Gets the tileset for the given map tile on the given map.
public static TiledMapTileset GetTileset(this TiledMapTile tile, TiledMap map)
Parameters
tileTiledMapTileThe tile
mapTiledMapThe map the tile is on
Returns
- TiledMapTileset
The tileset that the tile came from
GetTilesetTile(TiledMapTile, TiledMap, bool)
Gets the tileset tile on the given tileset for the given tile. If the tileset is already known, you should use GetTilesetTile(TiledMapTileset, TiledMapTile, TiledMap, bool) instead for performance.
public static TiledMapTilesetTile GetTilesetTile(this TiledMapTile tile, TiledMap map, bool createStub = true)
Parameters
tileTiledMapTileThe tile
mapTiledMapThe map the tile is on
createStubboolIf a tileset tile has no special properties, there is no pre-made object for it. If this boolean is true, a stub object with no extra data will be created instead of returning null.
Returns
- TiledMapTilesetTile
null if the tile is blank or the tileset tile if there is one or createStub is true
GetTilesetTile(TiledMapTileset, TiledMapTile, TiledMap, bool)
Gets the tileset tile on the given tileset for the given tile.
public static TiledMapTilesetTile GetTilesetTile(this TiledMapTileset tileset, TiledMapTile tile, TiledMap map, bool createStub = true)
Parameters
tilesetTiledMapTilesetThe tileset
tileTiledMapTileThe tile
mapTiledMapThe map the tile is on
createStubboolIf a tileset tile has no special properties, there is no pre-made object for it. If this boolean is true, a stub object with no extra data will be created instead of returning null.
Returns
- TiledMapTilesetTile
null if the tile is blank or the tileset tile if there is one or createStub is true
GetTilesetTile(TiledMapTileset, int, bool)
Gets the tileset tile on the given tileset for the given local id.
public static TiledMapTilesetTile GetTilesetTile(this TiledMapTileset tileset, int localId, bool createStub = true)
Parameters
tilesetTiledMapTilesetThe tileset
localIdintThe tile's local id
createStubboolIf a tileset tile has no special properties, there is no pre-made object for it. If this boolean is true, a stub object with no extra data will be created instead of returning null.
Returns
- TiledMapTilesetTile
null if the tile is blank or the tileset tile if there is one or createStub is true
IsInBounds(TiledMapTileLayer, int, int)
Returns whether the given position is in the bounds of the layer (that is, if each coordinate is >= 0 and if they are both smaller than the layer's width and height).
public static bool IsInBounds(this TiledMapTileLayer layer, int x, int y)
Parameters
Returns
- bool
Whether the position is in bounds of the layer
SetTile(TiledMap, LayerPosition, TiledMapTileset, TiledMapTilesetTile)
Sets the tiled map tile at the given location to the given tile from the given tileset.
If the passed tileset or tile is null, the tile at the location is removed instead.
public static void SetTile(this TiledMap map, LayerPosition pos, TiledMapTileset tileset, TiledMapTilesetTile tile)
Parameters
mapTiledMapThe map
posLayerPositionThe layer position
tilesetTiledMapTilesetThe tileset to use, or null to remove the tile
tileTiledMapTilesetTileThe tile to place, from the given tileset, or null to remove the tile
SetTile(TiledMap, LayerPosition, int)
Sets the tiled map tile at the given location to the given global tile identifier.
public static void SetTile(this TiledMap map, LayerPosition pos, int globalTile)
Parameters
mapTiledMapThe map
posLayerPositionThe layer position
globalTileintThe tile's global identifier to set
SetTile(TiledMap, string, int, int, TiledMapTileset, TiledMapTilesetTile)
Sets the tiled map tile at the given location to the given tile from the given tileset.
If the passed tileset or tile is null, the tile at the location is removed instead.
public static void SetTile(this TiledMap map, string layerName, int x, int y, TiledMapTileset tileset, TiledMapTilesetTile tile)
Parameters
mapTiledMapThe map
layerNamestringThe name of the layer
xintThe x coordinate
yintThe y coordinate
tilesetTiledMapTilesetThe tileset to use, or null to remove the tile
tileTiledMapTilesetTileThe tile to place, from the given tileset, or null to remove the tile
SetTile(TiledMap, string, int, int, int)
Sets the tiled map tile at the given location to the given global tile identifier.
public static void SetTile(this TiledMap map, string layerName, int x, int y, int globalTile)