Class Tile
A tile is an object on a Map that represents the covering of the ground (or the ground itself). To register a tile, use Register(string, int, Dictionary<Point, TextureRegion>, Point, ColorScheme, float, bool, Category, TextureRegion, Func<Direction2, Point?>, int?, Func<Point, float>, Type).
[JsonConverter(typeof(Tile.Converter))]
public class Tile
- Inheritance
-
Tile
- Derived
- Inherited Members
- Extension Methods
Constructors
Tile(string, string, int, Dictionary<Point, TextureRegion>, Dictionary<Direction2, Point[]>, ColorSettings, int[], bool, float, Category, TextureRegion, Func<Point, float>)
Creates a new tile with the given settings. To create an instance of a custom tile class, use Register(string, int, Dictionary<Point, TextureRegion>, Point, ColorScheme, float, bool, Category, TextureRegion, Func<Direction2, Point?>, int?, Func<Point, float>, Type).
protected Tile(string baseName, string name, int price, Dictionary<Point, TextureRegion> textures, Dictionary<Direction2, Point[]> regions, ColorSettings colorSettings, int[] colors, bool canBuy, float pathCostModifier, Tile.Category categories, TextureRegion icon, Func<Point, float> regionWeights)
Parameters
baseName
stringname
stringprice
inttextures
Dictionary<Point, TextureRegion>regions
Dictionary<Direction2, Point[]>colorSettings
ColorSettingscolors
int[]canBuy
boolpathCostModifier
floatcategories
Tile.Categoryicon
TextureRegionregionWeights
Func<Point, float>
Fields
BaseName
The name of this type of tile. Whereas Name has the index of its Colors appended to it, this one is just the type's name.
public readonly string BaseName
Field Value
BigTiles
public static readonly Tile[] BigTiles
Field Value
- Tile[]
CanBuy
A field that indicates whether this tile can be bought without the "ShowNonBuyable" cheat enabled
public readonly bool CanBuy
Field Value
Categories
The Tile.Category flags that this tile has.
public readonly Tile.Category Categories
Field Value
CheckeredHardwood
public static readonly Tile[] CheckeredHardwood
Field Value
- Tile[]
ColorSettings
The color settings used by this tile.
public readonly ColorSettings ColorSettings
Field Value
Colors
The indices of the colors in each ColorSettings entry that this tile has
public readonly int[] Colors
Field Value
- int[]
Concrete
public static readonly Tile[] Concrete
Field Value
- Tile[]
Dirt
public static readonly Tile[] Dirt
Field Value
- Tile[]
DirtPath
public static readonly Tile[] DirtPath
Field Value
- Tile[]
DirtRoad
public static readonly Tile[] DirtRoad
Field Value
- Tile[]
DirtRoadLines1
public static readonly Tile[] DirtRoadLines1
Field Value
- Tile[]
DirtRoadLines2
public static readonly Tile[] DirtRoadLines2
Field Value
- Tile[]
DirtWithGrass
public static readonly Tile[] DirtWithGrass
Field Value
- Tile[]
FlowerGrass
public static readonly Tile[] FlowerGrass
Field Value
- Tile[]
Grass
public static readonly Tile[] Grass
Field Value
- Tile[]
Icon
The build mode icon for this object, which represents the category / theme / mod that it comes from. If this value is nonnull, the icon will be displayed in the corner of the build mode button for this object.
public readonly TextureRegion Icon
Field Value
- TextureRegion
IntricateCarpet
public static readonly Tile[] IntricateCarpet
Field Value
- Tile[]
LargeConcreteTiles
public static readonly Tile[] LargeConcreteTiles
Field Value
- Tile[]
LongBoards
public static readonly Tile[] LongBoards
Field Value
- Tile[]
ModernBricks
public static readonly Tile[] ModernBricks
Field Value
- Tile[]
ModernTiles
public static readonly Tile[] ModernTiles
Field Value
- Tile[]
Name
The name of this specific tile. This is comprised of the BaseName with the Colors's index attached to it.
public readonly string Name
Field Value
OrnateHardwood
public static readonly Tile[] OrnateHardwood
Field Value
- Tile[]
PathCostModifier
A field that indicates the "cost" for pathfinding of this tile. The default modifier is 1, and it should not be set to a value lower than that.
public readonly float PathCostModifier
Field Value
Price
The price of this tile
public readonly int Price
Field Value
PuzzlePieces
public static readonly Tile[] PuzzlePieces
Field Value
- Tile[]
ReferencePrice
The reference price for tiles. Since Grass is replaced by Concrete in a newly created room, the two tiles have to cost the same. This is that price. This value is set to 5.
public const int ReferencePrice = 5
Field Value
RegionWeights
An optional weight function that determines how likely each variation texture is to be picked.
public readonly Func<Point, float> RegionWeights
Field Value
Regions
The texture regions this tile uses, which refer to entries in Textures.
public readonly Dictionary<Direction2, Point[]> Regions
Field Value
- Dictionary<Direction2, Point[]>
RicketyHardwood
public static readonly Tile[] RicketyHardwood
Field Value
- Tile[]
Road1
public static readonly Tile[] Road1
Field Value
- Tile[]
Road2
public static readonly Tile[] Road2
Field Value
- Tile[]
Road3
public static readonly Tile[] Road3
Field Value
- Tile[]
Road4
public static readonly Tile[] Road4
Field Value
- Tile[]
Road5
public static readonly Tile[] Road5
Field Value
- Tile[]
Rocks
public static readonly Tile[] Rocks
Field Value
- Tile[]
Sand
public static readonly Tile[] Sand
Field Value
- Tile[]
SimpleCarpet
public static readonly Tile[] SimpleCarpet
Field Value
- Tile[]
SmallCheckeredHardwood
public static readonly Tile[] SmallCheckeredHardwood
Field Value
- Tile[]
SoftCarpet
public static readonly Tile[] SoftCarpet
Field Value
- Tile[]
StraightBoards
public static readonly Tile[] StraightBoards
Field Value
- Tile[]
Textures
The texture atlas used for this tile.
public readonly Dictionary<Point, TextureRegion> Textures
Field Value
- Dictionary<Point, TextureRegion>
Tiles
A registry of all tiles that exist in the game and its mods
public static readonly ReadOnlyDictionary<string, Tile[]> Tiles
Field Value
Water
public static readonly Tile[] Water
Field Value
- Tile[]
Methods
Draw(GameTime, object, Map, Point, int, Vector2, float, float, ICollection<Item>, bool, Func<Point, int, Tile>)
Draws this tile at the given position in the world using a Microsoft.Xna.Framework.Graphics.SpriteBatch or MLEM.Graphics.StaticSpriteBatch
public virtual bool Draw(GameTime time, object batch, Map map, Point pos, int floor, Vector2 drawPos, float scale, float depthOffset, ICollection<StaticSpriteBatch.Item> items, bool hasStaticContext, Func<Point, int, Tile> getRelatedTileFunc = null)
Parameters
time
GameTimeThe game's current time.
batch
objectThe sprite batch to use for drawing, which can either be a Microsoft.Xna.Framework.Graphics.SpriteBatch or a MLEM.Graphics.StaticSpriteBatch.
map
MapThe map that the tile is on.
pos
PointThe position that the tile is on.
floor
intThe floor that this tile is on.
drawPos
Vector2The position, in screen space, to draw at.
scale
floatThe scale to draw the tile with.
depthOffset
floatA depth offset that can optionally be added to this tile's draw depth.
items
ICollection<StaticSpriteBatch.Item>The MLEM.Graphics.StaticSpriteBatch.Item collection that added items can optionally be added to.
hasStaticContext
boolWhether this tile also has a static context, that is, whether it will already be drawn using a MLEM.Graphics.StaticSpriteBatch.
getRelatedTileFunc
Func<Point, int, Tile>A function that can optionally be supplied to override the GetTile(Point, int) method when checking for neighboring tiles. This is useful for when tile placement in the world is mocked, for example.
Returns
- bool
Whether this tile was fully drawn. If the
batch
is a MLEM.Graphics.StaticSpriteBatch and false is returned, this tile will be marked as an animated tile, causing it to draw every frame.
DrawUi(Element, GameTime, SpriteBatch, float)
Draws this tile on the given ui element, in ui space
public virtual void DrawUi(Element e, GameTime time, SpriteBatch batch, float drawScale)
Parameters
e
ElementThe element to draw on
time
GameTimeThe game's current time.
batch
SpriteBatchThe sprite batch to use for drawing
drawScale
floatThe scale to draw the tile with.
GetAutoTileBorder(Map, Point, int, Point, Tile, int)
Returns the texture that should be displayed as the border when a AutoTile draws next to this tile. By default, this method returns values only for some basegame tiles.
public virtual (Func<int, TextureRegion> Texture, Color Color, float Priority)? GetAutoTileBorder(Map map, Point pos, int floor, Point neighbor, Tile neighborTile, int layer)
Parameters
map
MapThe map.
pos
PointThe position of this tile.
floor
intThe floor that this tile is on.
neighbor
PointThe position of the neighbor tile querying the auto tile border on this tile.
neighborTile
TileThe neighbor tile querying the auto tile border on this tile.
layer
intThe layer of the border being drawn. By default, tiles use layer 0 for regular borders, and layer 1 for special borders, like the little "cliff" that displays on water tiles.
Returns
- (Func<int, TextureRegion> Texture, Color Color, float Priority)?
The texture, or null to draw no auto-tile border.
GetDepth(Map, Vector2, float, float, bool)
Gets the depth that should be used for drawing a Tile at the given position
public static float GetDepth(Map map, Vector2 worldPos, float floor, float offset = 0, bool borderOffset = true)
Parameters
map
MapThe map to get depth on.
worldPos
Vector2The position to get depth for, in tile coordinates
floor
floatThe floor to get depth for.
offset
floatAn offset added to the depth value
borderOffset
boolWhether the map border offset should be applied to the camera rotation using ApplyCameraRotation(Vector2, bool, Direction2?).
Returns
- float
The depth to pass to the draw call
GetPrice()
Returns the price for this tile, which is normally based on Price.
public virtual float GetPrice()
Returns
- float
The price for this tile.
GetVariationTexture(Direction2, Point)
Returns a random texture that should be displayed at the given position, based on the Textures variations that this tile has. If a tile only has one variation texture, this method always returns that texture.
protected Point GetVariationTexture(Direction2 direction, Point pos)
Parameters
direction
Direction2The camera rotation.
pos
PointThe position that the tile is at.
Returns
- Point
The texture to display at the location.
GetVisualOffset(Direction2, int, int)
Returns the visual offset of the given x
and y
values, based on the given direction
, which is usually the game's CameraRotation.
protected static Point GetVisualOffset(Direction2 direction, int x, int y)
Parameters
direction
Direction2The rotation.
x
intThe x coordinate to offset.
y
intThe y coordinate to offset.
Returns
- Point
The visual offset.
OnNeighborChanged(Map, Point, Point, int)
A method that is called when a neighboring Tile on the Map changes. This method does nothing by default, but is overriden by AutoTile to notify neighboring tiles of changes.
public virtual void OnNeighborChanged(Map map, Point pos, Point neighbor, int floor)
Parameters
map
MapThe map that the tile is on.
pos
PointThe position that the tile is on.
neighbor
PointThe position of the tile that changed.
floor
intThe floor that this tile and the neighbor are on.
Register(string, int, Dictionary<Point, TextureRegion>, Point, ColorScheme, float, bool, Category, TextureRegion, Func<Direction2, Point?>, int?, Func<Point, float>, Type)
Registers a new tile with the given settings.
public static Tile[] Register(string name, int price, Dictionary<Point, TextureRegion> textures, Point textureRegion, ColorScheme color, float pathCostModifier = 1, bool canBuy = true, Tile.Category categories = Category.None, TextureRegion icon = null, Func<Direction2, Point?> variations = null, int? defaultColor = null, Func<Point, float> regionWeights = null, Type constructedType = null)
Parameters
name
stringThe name that the tile should have.
price
intThe tile's price.
textures
Dictionary<Point, TextureRegion>The texture atlas to use.
textureRegion
PointThe texture region that this tile should use for rendering.
color
ColorSchemeThe color scheme that this tile should have.
pathCostModifier
floatThe path cost modifier, >= 1, that this tile should have.
canBuy
boolWhether or not the tile can be bought in the tile tool.
categories
Tile.CategoryThis tile's Tile.Category flags.
icon
TextureRegionThe build mode category icon of this object.
variations
Func<Direction2, Point?>An optional set of variation textures that should be used based on the given camera rotation.
defaultColor
int?The color that this tile should display with in the tile tool by default.
regionWeights
Func<Point, float>An optional weight function that determines how likely each variation texture is to be picked.
constructedType
TypeThe type that tiles should be constructed from, or null to construct Tile instances.
Returns
- Tile[]
Register(string, int, Dictionary<Point, TextureRegion>, Point, ColorScheme[], float, bool, Category, TextureRegion, Func<Direction2, Point?>, int[], Func<Point, float>, Type)
Registers a new tile with the given settings.
public static Tile[] Register(string name, int price, Dictionary<Point, TextureRegion> textures, Point textureRegion, ColorScheme[] colors, float pathCostModifier = 1, bool canBuy = true, Tile.Category categories = Category.None, TextureRegion icon = null, Func<Direction2, Point?> variations = null, int[] defaultColors = null, Func<Point, float> regionWeights = null, Type constructedType = null)
Parameters
name
stringThe name that the tile should have.
price
intThe tile's price.
textures
Dictionary<Point, TextureRegion>The texture atlas to use.
textureRegion
PointThe texture region that this tile should use for rendering.
colors
ColorScheme[]The color scheme that this tile should have.
pathCostModifier
floatThe path cost modifier, >= 1, that this tile should have.
canBuy
boolWhether or not the tile can be bought in the tile tool.
categories
Tile.CategoryThis tile's Tile.Category flags.
icon
TextureRegionThe build mode category icon of this object.
variations
Func<Direction2, Point?>An optional set of variation textures that should be used based on the given camera rotation.
defaultColors
int[]The colors that this tile should display with in the tile tool by default.
regionWeights
Func<Point, float>An optional weight function that determines how likely each variation texture is to be picked.
constructedType
TypeThe type that tiles should be constructed from, or null to construct Tile instances.
Returns
- Tile[]
Register(string, int, Dictionary<Point, TextureRegion>, Point[], ColorScheme[], float, bool, Category, TextureRegion, Func<Direction2, Point[]>, int[], Func<Point, float>, Type)
Registers a new tile with the given settings.
public static Tile[] Register(string name, int price, Dictionary<Point, TextureRegion> textures, Point[] textureRegions, ColorScheme[] colors, float pathCostModifier = 1, bool canBuy = true, Tile.Category categories = Category.None, TextureRegion icon = null, Func<Direction2, Point[]> variations = null, int[] defaultColors = null, Func<Point, float> regionWeights = null, Type constructedType = null)
Parameters
name
stringThe name that the tile should have.
price
intThe tile's price.
textures
Dictionary<Point, TextureRegion>The texture atlas to use.
textureRegions
Point[]The texture regions that this tile should use for rendering, from which a random value will be chosen for each tile.
colors
ColorScheme[]The color scheme that this tile should have.
pathCostModifier
floatThe path cost modifier, >= 1, that this tile should have.
canBuy
boolWhether or not the tile can be bought in the tile tool.
categories
Tile.CategoryThis tile's Tile.Category flags.
icon
TextureRegionThe build mode category icon of this object.
variations
Func<Direction2, Point[]>An optional set of variation textures that should be used based on the given camera rotation.
defaultColors
int[]The default colors that will be passed to the ColorSettings Defaults.
regionWeights
Func<Point, float>An optional weight function that determines how likely each variation texture is to be picked.
constructedType
TypeThe type that tiles should be constructed from, or null to construct Tile instances.
Returns
- Tile[]
The registered tiles.
Register(string, int, Dictionary<Point, TextureRegion>, Point[], ColorSettings, float, bool, Category, TextureRegion, Func<Direction2, Point[]>, Func<Point, float>, Type)
Registers a new tile with the given settings.
public static Tile[] Register(string name, int price, Dictionary<Point, TextureRegion> textures, Point[] textureRegions, ColorSettings colors, float pathCostModifier = 1, bool canBuy = true, Tile.Category categories = Category.None, TextureRegion icon = null, Func<Direction2, Point[]> variations = null, Func<Point, float> regionWeights = null, Type constructedType = null)
Parameters
name
stringThe name that the tile should have.
price
intThe tile's price.
textures
Dictionary<Point, TextureRegion>The texture atlas to use.
textureRegions
Point[]The texture regions that this tile should use for rendering, from which a random value will be chosen for each tile.
colors
ColorSettingsThe color scheme that this tile should have.
pathCostModifier
floatThe path cost modifier, >= 1, that this tile should have.
canBuy
boolWhether or not the tile can be bought in the tile tool.
categories
Tile.CategoryThis tile's Tile.Category flags.
icon
TextureRegionThe build mode category icon of this object.
variations
Func<Direction2, Point[]>An optional set of variation textures that should be used based on the given camera rotation.
regionWeights
Func<Point, float>An optional weight function that determines how likely each variation texture is to be picked.
constructedType
TypeThe type that tiles should be constructed from, or null to construct Tile instances.
Returns
- Tile[]
The registered tiles.