TileLayer
Declaration
public class Strawberry.Graphics.Layers.TileLayer
A layer that renders a tilemap from a single texture. Tiles are stored persistently (not cleared every frame) and can be pushed either by grid index (column, row) or by an exact texture source rectangle. Supports loading the JSON format exported by TileMap Studio.
Inherits: Strawberry.Graphics.Layers.Layer
Constructors
TileLayer
void TileLayer()
TileLayer
void TileLayer(int maxBatchCount)
Parameters:
| Name | Type | Description |
|---|---|---|
maxBatchCount |
System.Int32 |
Properties
ActiveShader
Gets the currently active shader used for tile rendering.
BasicShader ActiveShader { get }
GraphicsContext
Gets the graphics context for the current scene.
IGraphicsContext GraphicsContext { get }
DrawCalls
Gets or sets the number of draw calls performed during the most recent render pass.
int DrawCalls { get set }
Texture
The single texture from which all tiles are sampled.
Texture Texture { get set }
GridSize
The size of a single tile in pixels, used when pushing tiles by grid index. For example, (16, 16) means each tile is 16px wide and 16px tall in the texture. This is set automatically when loading a TileMap Studio JSON file.
Vector2 GridSize { get set }
Color
The color tint applied to every tile by default. Default is white (no tint). Individual tiles pushed with a custom color override this.
Color Color { get set }
Scale
Global scale applied to every tile's destination size. Default is (1, 1).
Vector2 Scale { get set }
Offset
Global offset applied to every tile's world position. Useful for scrolling the entire tilemap (e.g. for parallax or camera offset). Default is (0, 0).
Vector2 Offset { get set }
TileCount
Gets the number of tiles currently stored in this layer.
int TileCount { get }
Methods
Initialize override
void Initialize(Scene scene)
Parameters:
| Name | Type | Description |
|---|---|---|
scene |
Strawberry.Core.Scene |
SetShader
void SetShader(BasicShader shader)
Parameters:
| Name | Type | Description |
|---|---|---|
shader |
Strawberry.Graphics.BasicShader |
ResetShader
void ResetShader()
SetBlendMode
void SetBlendMode(string name)
Parameters:
| Name | Type | Description |
|---|---|---|
name |
System.String |
Push
Pushes a tile from the texture at tile index tileCol, tileRow to the world position worldPosition. The tile's source rectangle is computed as (tileCol * GridSize.X, tileRow * GridSize.Y, (tileCol+1) * GridSize.X, (tileRow+1) * GridSize.Y). For example, with a 32×32 grid, tile (2, 1) samples from (64, 32, 96, 64).
void Push(int tileCol, int tileRow, Vector2 worldPosition)
Parameters:
| Name | Type | Description |
|---|---|---|
tileCol |
System.Int32 |
The column index of the tile in the texture (0-based). |
tileRow |
System.Int32 |
The row index of the tile in the texture (0-based). |
worldPosition |
Strawberry.Math.Vector2 |
The world-space position (top-left corner) where the tile will be drawn. |
Push
Pushes a tile from the texture at tile index tileCol, tileRow to the grid cell cellX, cellY in world space. The destination world position is computed as (cellX * GridSize.X, cellY * GridSize.Y), so the tile snaps to the layer's grid. The tile's source rectangle is also computed from tileCol and tileRow using GridSize.
void Push(int tileCol, int tileRow, int cellX, int cellY)
Parameters:
| Name | Type | Description |
|---|---|---|
tileCol |
System.Int32 |
|
tileRow |
System.Int32 |
|
cellX |
System.Int32 |
|
cellY |
System.Int32 |
Push
Pushes a tile from the texture at tile index tileCol, tileRow to the world position worldPosition, with a custom destination size and color.
void Push(int tileCol, int tileRow, Vector2 worldPosition, Vector2 destinationSize, Color color)
Parameters:
| Name | Type | Description |
|---|---|---|
tileCol |
System.Int32 |
|
tileRow |
System.Int32 |
|
worldPosition |
Strawberry.Math.Vector2 |
|
destinationSize |
Strawberry.Math.Vector2 |
|
color |
Strawberry.Graphics.Color |
PushExact
Pushes a tile using an exact texture source rectangle specified by texLeft, texTop, texRight, texBottom (in pixels). The tile is drawn at worldPosition with the size destinationSize (in world units).
void PushExact(float texLeft, float texTop, float texRight, float texBottom, Vector2 worldPosition, Vector2 destinationSize)
Parameters:
| Name | Type | Description |
|---|---|---|
texLeft |
System.Single |
|
texTop |
System.Single |
|
texRight |
System.Single |
|
texBottom |
System.Single |
|
worldPosition |
Strawberry.Math.Vector2 |
|
destinationSize |
Strawberry.Math.Vector2 |
PushExact
Pushes a tile using an exact texture source rectangle specified by texLeft, texTop, texRight, texBottom (in pixels), with a custom color tint.
void PushExact(float texLeft, float texTop, float texRight, float texBottom, Vector2 worldPosition, Vector2 destinationSize, Color color)
Parameters:
| Name | Type | Description |
|---|---|---|
texLeft |
System.Single |
|
texTop |
System.Single |
|
texRight |
System.Single |
|
texBottom |
System.Single |
|
worldPosition |
Strawberry.Math.Vector2 |
|
destinationSize |
Strawberry.Math.Vector2 |
|
color |
Strawberry.Graphics.Color |
PushExact
Pushes a tile using an exact texture source rectangle, with the destination size automatically set to (texRight - texLeft, texBottom - texTop) (i.e. 1:1 pixel mapping).
void PushExact(float texLeft, float texTop, float texRight, float texBottom, Vector2 worldPosition)
Parameters:
| Name | Type | Description |
|---|---|---|
texLeft |
System.Single |
|
texTop |
System.Single |
|
texRight |
System.Single |
|
texBottom |
System.Single |
|
worldPosition |
Strawberry.Math.Vector2 |
PushBlock
Pushes a rectangular block of tiles from the texture to a rectangular block of cells in world space. Tile (tileColStart + i, tileRowStart + j) is drawn at world cell (cellXStart + i, cellYStart + j).
void PushBlock(int tileColStart, int tileRowStart, int cellXStart, int cellYStart, int cellsWide, int cellsHigh)
Parameters:
| Name | Type | Description |
|---|---|---|
tileColStart |
System.Int32 |
|
tileRowStart |
System.Int32 |
|
cellXStart |
System.Int32 |
|
cellYStart |
System.Int32 |
|
cellsWide |
System.Int32 |
|
cellsHigh |
System.Int32 |
PushFill
Pushes the same tile (by index) to a rectangular block of cells in world space.
void PushFill(int tileCol, int tileRow, int cellXStart, int cellYStart, int cellsWide, int cellsHigh)
Parameters:
| Name | Type | Description |
|---|---|---|
tileCol |
System.Int32 |
|
tileRow |
System.Int32 |
|
cellXStart |
System.Int32 |
|
cellYStart |
System.Int32 |
|
cellsWide |
System.Int32 |
|
cellsHigh |
System.Int32 |
Clear
Removes all tiles from this layer.
void Clear()
LoadFromTileMapStudio
Loads a single layer from a TileMap Studio JSON file. The tileSize from the JSON is used to set GridSize. The tilesets section is completely ignored — the user provides their own texture. Only the layer whose layerName matches is loaded; all other layers are skipped.
int LoadFromTileMapStudio(string jsonPath, string layerName, Texture texture)
Parameters:
| Name | Type | Description |
|---|---|---|
jsonPath |
System.String |
Path to the .json file exported by TileMap Studio. |
layerName |
System.String |
The name of the layer to load (matches the layer's "name" field in the JSON). |
texture |
Strawberry.Graphics.Texture |
The texture to use for all tiles. The tilesets' embedded data is ignored. |
Returns: The number of tiles loaded. Returns 0 if the layer was not found or was empty.
LoadFromTileMapStudioJson
Loads a single layer from a TileMap Studio JSON string. See LoadFromTileMapStudio for details.
int LoadFromTileMapStudioJson(string jsonText, string layerName, Texture texture)
Parameters:
| Name | Type | Description |
|---|---|---|
jsonText |
System.String |
The JSON text exported by TileMap Studio. |
layerName |
System.String |
The name of the layer to load. |
texture |
Strawberry.Graphics.Texture |
The texture to use for all tiles. |
Returns: The number of tiles loaded.
Render override
void Render()