Class AutoTile
An auto-tile is a Tile that visually connects to other tiles around it, while leaving a border around tiles that it doesn't connect to. Implementors can override ConnectsToTile(Map, Point, int, int, int, Func<Point, int, Tile>) to edit this behavior.
public class AutoTile : Tile
- Inheritance
-
AutoTile
- Derived
- Inherited Members
- Extension Methods
Constructors
AutoTile(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 AutoTile(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>
Properties
DefaultBorderTile
Returns the tile information that should be used in place of GetAutoTileBorder(Map, Point, int, Point, Tile, int) if no relevant border tiles are around. This defaults to the grass tile border with the default color.
protected virtual (Func<int, TextureRegion>, Color) DefaultBorderTile { get; }
Property Value
Methods
ConnectsToTile(Map, Point, int, int, int, Func<Point, int, Tile>)
Override this method to determine what other tiles this auto-tile should connect to. By default, auto-tiles connect to other tiles of the same type.
protected virtual bool ConnectsToTile(Map map, Point pos, int floor, int x, int y, Func<Point, int, Tile> getRelatedTileFunc = null)
Parameters
map
MapThe map.
pos
PointThe position of the tile.
floor
intThe floor of the tile.
x
intThe offset from
pos
in the x axis.y
intThe offset from
pos
in the y axis.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 should connect to the tile at the offset position.
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 override 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.
DrawBorder(object, Map, Point, int, int, Vector2, float, float, ICollection<Item>, Func<Point, int, Tile>)
Draws the auto-tile border.
protected void DrawBorder(object batch, Map map, Point pos, int floor, int layer, Vector2 drawPos, float scale, float depthOffset, ICollection<StaticSpriteBatch.Item> items, Func<Point, int, Tile> getRelatedTileFunc = null)
Parameters
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 to draw at.
layer
intThe layer of the border to draw. By default, tiles use layer 0 for regular borders, and layer 1 for special borders, like the little "cliff" that displays on water tiles. This is passed to GetAutoTileBorder(Map, Point, int, Point, Tile, int).
drawPos
Vector2The position, in screen space, to draw at.
scale
floatThe scale to draw the tile with.
depthOffset
floatA depth offset that is optionally added to the calculated draw depth.
items
ICollection<StaticSpriteBatch.Item>The MLEM.Graphics.StaticSpriteBatch.Item collection that added items can optionally be added to.
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.
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 override void OnNeighborChanged(Map map, Point pos, Point neighbor, int floor)