Skip to content

PhysicsAPI reference

Class TileGrid

Namespace: MicroEngine.World
Assembly: MicroEngine.Physics.Tiles.dll
Guide: Tile maps and collision

A collision grid backed by a TileLayer and a per-id flag table. Cells outside the map use OutsideFlags (solid by default, so levels are closed).

C#
public sealed class TileGrid : ICollisionGrid

Inheritance

object ← TileGrid

Implements

ICollisionGrid

Constructors

TileGrid(TileLayer, int, IReadOnlyDictionary<int, TileFlags>)

Creates a grid; ids missing from flags have no flags (empty).

C#
public TileGrid(TileLayer layer, int tileSize, IReadOnlyDictionary<int, TileFlags> flags)

Parameters

layer TileLayer

The tile ids.

tileSize int

Tile size in pixels; must be positive.

flags IReadOnlyDictionary<int, TileFlags>

Flags per tile id; copied.

Exceptions

ArgumentOutOfRangeException

tileSize is not positive.

Properties

Layer

The tile ids the grid reads. Changing a tile in the layer changes collisions at once.

C#
public TileLayer Layer { get; }

Property Value

TileLayer

OutsideFlags

Flags of every cell outside the map when OutsideRule gives none (solid by default).

C#
public TileFlags OutsideFlags { get; set; }

Property Value

TileFlags

OutsideRule

Optional override for open edges, e.g. a platformer’s bottom pit must not be solid.

C#
public Func<int, int, TileFlags?>? OutsideRule { get; set; }

Property Value

Func<int, int, TileFlags?>?

PixelHeight

Height of the map in pixels.

C#
public int PixelHeight { get; }

Property Value

int

PixelWidth

Width of the map in pixels.

C#
public int PixelWidth { get; }

Property Value

int

TileSize

Size of a square tile in pixels.

C#
public int TileSize { get; }

Property Value

int

Methods

FlagsAt(int, int)

The flags of the tile at (tileX, tileY); outside the map, OutsideRule or OutsideFlags.

C#
public TileFlags FlagsAt(int tileX, int tileY)

Parameters

tileX int

tileY int

Returns

TileFlags

SetFlags(int, TileFlags)

Sets the flags of every tile with id id.

C#
public void SetFlags(int id, TileFlags flags)

Parameters

id int

flags TileFlags