TileLayer

Tily. TileLayer

new TileLayer(container)

A layer of tiles displayed in a buffer or a cell.

Parameters
Name Type Description
container Tily.Buffer | Tily.Cell

The buffer or cell that this layer belongs to.

Members

background :string

The colour to use for this layer's tile backgrounds. If the string is empty, tile backgrounds won't be rendered.

Default Value:
  • ""

backgroundMap :string

Optional map of background colours

Default Value:
  • null

centered :boolean

True if the text in this layer's tiles should be centered.

Default Value:
  • false

clip :boolean

Whether or not to clip this layer's tiles at their edges.

Default Value:
  • false

compositeMode :string

The composite operation to use when drawing this layer.

Default Value:
  • "source-over"

container :Tily.Buffer|Tily.Cell

The buffer or cell that this layer belongs to.

font :string

The font to use for this layer's tiles.

Default Value:
  • "sans-serif"

foreground :string

The colour to use for this layer's tile characters.

Default Value:
  • "white"

foregroundMap :string

Optional map of foreground colours

Default Value:
  • null

opacity :number

The opacity of this layer's tiles.

Default Value:
  • 1

tiles :Array.<string>

An array of strings for each tile. If any element in this array has length greater than 1, the string characters will be rendered on top of each other. If any element is an empty string, the tile won't be rendered.

Methods

(static) fromData(container, data) → {Tily.TileLayer}

Create a tile layer from data.

Parameters
Name Type Description
container Tily.Buffer | Tily.Cell

The buffer or cell that the layer belongs to.

data Object

Serialized buffer layer data.

Returns

A buffer layer created from the provided data.

Type
Tily.TileLayer

clear(x1opt, y1opt, x2opt, y2opt)

Clear all tiles in a rectangular region. If x2 and y2 are not specified then clear from (x1, y1) to the bottom-right corner, and if no coordinates are specified then clear the entire layer. Top-left corner is inclusive, bottom-right corner is exclusive.

Parameters
Name Type Attributes Description
x1 number <optional>

The x-coordinate of the top-left corner of the region.

y1 number <optional>

The y-coordinate of the top-left corner of the region.

x2 number <optional>

The x-coordinate of the bottom-right corner of the region.

y2 number <optional>

The y-coordinate of the bottom-right corner of the region.

draw(context, tileSize, tl, br)

Render this layer onto the specified context. If a tile has a string with length greater than 1, draw each character of the string on top of each other.

Parameters
Name Type Description
context CanvasRenderingContext2D

The context to render the layer onto.

tileSize number

The size of each tile measured in pixels.

tl Tily.utility.vec2

The top-left tile position currently in view.

br Tily.utility.vec2

The bottom-right tile position currently in view.

fill(character, x1opt, y1opt, x2opt, y2opt)

Set the characters for all tiles in a rectangular region. If x2 and y2 are not specified then fill from (x1, y1) to the bottom-right corner, and if no coordinates are specified then fill the entire layer. Top-left corner is inclusive, bottom-right corner is exclusive.

Parameters
Name Type Attributes Description
character string

The character or characters to set.

x1 number <optional>

The x-coordinate of the top-left corner of the region.

y1 number <optional>

The y-coordinate of the top-left corner of the region.

x2 number <optional>

The x-coordinate of the bottom-right corner of the region.

y2 number <optional>

The y-coordinate of the bottom-right corner of the region.

getData() → {Object}

Get serializable data for this tile layer.

Returns

This tile layer's data.

Type
Object

getTile(x, y) → {string}

Get the characters at the specified tile position, or an empty string if there are no characters at this tile position.

Parameters
Name Type Description
x number

The x-coordinate of the position.

y number

The y-coordinate of the position.

Returns

The character or characters at the specified position.

Type
string

resize(width, height)

Rearrange the tiles in this layer so they align with the specified width and height.

Parameters
Name Type Description
width number

The new layer width.

height number

The new layer height.

setTile(x, y, character, foreground, background) → {boolean}

Set the characters at the specified tile position.

Parameters
Name Type Description
x number

The x-coordinate of the position.

y number

The y-coordinate of the position.

character string

The character or characters to set.

foreground string

The foreground colour for this tile, or null to use default

background string

The background colour for this tile, or null to use default

Returns

True if the tile was set successfully.

Type
boolean