CI / build-test (push) Failing after 1m4s
TileSet maps ids to texture regions with tints (0 = empty), TileGrid is a bounds-checked dense ushort grid, and the Tilemap component places a grid in the world per render layer. UseTilemaps() inserts TilemapRenderSystem before the flush; it submits only the camera-visible cell range (TilemapMath.VisibleCells), so frame cost scales with the screen, not the grid. Demonstrated in the sample as a checkerboard floor; Tiled loading stays on the roadmap on top of this API.
48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using Friflo.Engine.ECS;
|
|
using Microsoft.Xna.Framework;
|
|
using MrGameEng.Graphics;
|
|
|
|
namespace MrGameEng.Tilemaps;
|
|
|
|
/// <summary>
|
|
/// Tilemap component: a <see cref="TileGrid"/> of ids drawn with a <see cref="TileSet"/>.
|
|
/// Cell (0,0) sits at <see cref="Origin"/>, cells are <see cref="TileSize"/> world units square.
|
|
/// Only the cells visible through the camera are submitted each frame, so grids can be large.
|
|
/// Create via the constructor — the struct default has no grid and draws nothing.
|
|
/// </summary>
|
|
public struct Tilemap : IComponent
|
|
{
|
|
/// <summary>Tile definitions; ids in the grid index into it.</summary>
|
|
public TileSet? TileSet;
|
|
|
|
/// <summary>The cells. Mutating ids takes effect next frame.</summary>
|
|
public TileGrid? Grid;
|
|
|
|
/// <summary>World position of the top-left corner of cell (0,0).</summary>
|
|
public Vector2 Origin;
|
|
|
|
/// <summary>Cell size in world units.</summary>
|
|
public float TileSize;
|
|
|
|
/// <summary>Render layer of the whole map.</summary>
|
|
public LayerId Layer;
|
|
|
|
/// <summary>Draw order within the layer (smaller = drawn first / behind).</summary>
|
|
public float Depth;
|
|
|
|
/// <summary>Tint multiplied into every tile on top of its <see cref="TileDef.Color"/>.</summary>
|
|
public Color Color;
|
|
|
|
/// <summary>Creates a tilemap at world origin.</summary>
|
|
public Tilemap(TileGrid grid, TileSet tileSet, float tileSize, LayerId layer = default)
|
|
{
|
|
Grid = grid;
|
|
TileSet = tileSet;
|
|
TileSize = tileSize;
|
|
Layer = layer;
|
|
Origin = Vector2.Zero;
|
|
Depth = 0f;
|
|
Color = Color.White;
|
|
}
|
|
}
|