Buffer

Tily. Buffer

new Buffer(width, height, optionsopt)

A buffer containing tile layers that can be rendered in the Tily canvas.

Parameters
Name Type Attributes Description
width number

The width of the buffer in tiles.

height number

The height of the buffer in tiles.

options BufferOptions <optional>

An optional options object for configuring the buffer.

Extends

Members

activeTiles :Array.<Tily.ActiveTile>

An array of active tiles contained in this buffer.

Inherited From:

activeTilesMap :Object

A map of active tiles, with hashed tile positions as keys and an array of tiles at a position as values.

Inherited From:

canvas :HTMLElement

The canvas element to render this buffer onto.

Inherited From:

context :CanvasRenderingContext2D

The canvas context to render onto.

Inherited From:

layers :Array.<Tily.TileLayer>

The layers contained in this buffer.

offset :Tily.utility.vec2

A camera offset position for this buffer measured in pixels.

Overrides:

offsetPixels :Tily.utility.vec2

The offset of this buffer measured in pixels, as a Tily.utility.vec2 object.

Inherited From:

(nullable) offsetTransition :Tily.OffsetTransition

The currently running offset transition or null if there is no transition currently running.

Inherited From:
Default Value:
  • null

options :BufferOptions

Options for configuring this buffer.

Inherited From:

scale :number

The number of tiles currently visible along the locked axis.

Overrides:

(nullable) scaleTransition :Tily.ScaleTransition

The currently running scale transition or null if there is no transition currently running.

Inherited From:
Default Value:
  • null

size :Size

The size of this buffer measured in tiles.

Inherited From:

tileSize :number

The side length of each tile measured in pixels.

Overrides:

viewSize :Size

The size of the viewport measured in tiles.

Inherited From:

Methods

(static) deserialize(s) → {Tily.Buffer}

Deserialize the JSON data into a buffer.

Parameters
Name Type Description
s string

The JSON data to deserialize.

Returns

The deserialized buffer.

Type
Tily.Buffer

(static) fromData(data) → {Tily.Buffer}

Create a buffer from data.

Parameters
Name Type Description
data Object

Serialized buffer data.

Returns

A buffer created from the provided data.

Type
Tily.Buffer

addActiveTile(…tiles) → {Tily.ActiveTile|array}

Add an active tile or multiple active tiles to this buffer.

Inherited From:
Parameters
Name Type Attributes Description
tiles Tily.ActiveTile <repeatable>

The tile(s) to add.

Returns

The tile(s) that were added

Type
Tily.ActiveTile | array

addLayer(layeropt, nullable, zopt) → {Tily.TileLayer}

Add a layer to this buffer at the specified z-index. If the z-index is undefined, add the layer on top of existing layers, and if the z-index is -1, add the layer below existing layers.

Parameters
Name Type Attributes Description
layer Tily.TileLayer <optional>
<nullable>

The layer to add. If null, add an empty new layer.

z number <optional>

The z-index at which to add the layer. If this is -1, the layer will be added below existing layers and if it is undefined the layer will be added above existing layers.

Returns

The layer that was added.

Type
Tily.TileLayer

draw(context, elapsedTime, width, height)

Render this buffer's layers onto the specified context.

Parameters
Name Type Description
context CanvasRenderingContext2D

The context to render the buffer onto.

elapsedTime number

The time elapsed in seconds since the last draw call.

width number

The width of the canvas in pixels.

height number

The height of the canvas in pixels.

getData() → {Object}

Get serializable data for this buffer.

Returns

This buffer's data.

Type
Object

getPosition(x, y) → {Tily.utility.vec2}

Return the tile position for the specified pixel position, based on the current offset and scale.

Inherited From:
Parameters
Name Type Description
x number

The x-coordinate of the pixel position.

y number

The y-coordinate of the pixel position.

Returns

The tile position currently at the specified pixel position.

Type
Tily.utility.vec2

getTileInfo(x, y) → {BufferTileInfo}

Get information about the tiles and active tiles at a tile position.

Overrides:
Parameters
Name Type Description
x number

The x-coordinate of the tile position.

y number

The y-coordinate of the tile position.

Returns

Information about the tiles at the specified position.

Type
BufferTileInfo

moveLayer(zFrom, zTo, relative) → {boolean}

Move a layer from one z-index to another z-index, either an absolute value or relative to the layer's current z-index.

Parameters
Name Type Description
zFrom number

The z-index of the layer to move.

zTo number

The z-index to move the layer to.

relative boolean

If this is true, the layer will be moved relative to it's current z-index.

Returns

True if a layer was moved successfully.

Type
boolean

moveOffset(x, y, optionsopt)

Move the offset with an optional transition animation.

Inherited From:
Parameters
Name Type Attributes Description
x number

The x-coordinate of the target offset position.

y number

The y-coordinate of the target offset position.

options MoveOffsetTransitionOptions <optional>

An optional options object.

removeActiveTile(tile)

Remove an active tile from this buffer.

Inherited From:
Parameters
Name Type Description
tile Tily.ActiveTile

The tile to remove.

removeAllActiveTiles()

Remove all active tiles from this buffer.

removeAllLayers()

Remove all layers from this buffer.

removeLayer(zopt) → {Tily.TileLayer}

Remove a layer at the specified z-index. If the z-index is undefined, remove the top layer and if the z-index is -1, remove the bottom layer. The removed layer is returned.

Parameters
Name Type Attributes Description
z number <optional>

The z-index of the layer to remove. If this is -1, the bottom layer will be removed and if it is undefined the top layer will be removed.

Returns

The layer that was removed.

Type
Tily.TileLayer

resize(width, height)

Resize this buffer's layers.

Parameters
Name Type Description
width number

The new width.

height number

The new height.

serialize() → {string}

Serialize this buffer and return the serialized JSON data.

Returns

This buffer serialized as JSON data.

Type
string

updateActiveTilesMap(tl, br) → {Array.<Tily.ActiveTile>}

Update the active tiles map and get a list of active tiles currently in view.

Inherited From:
Parameters
Name Type Description
tl Tily.utility.vec2

The top-left tile position currently in view.

br Tily.utility.vec2

The bottom-right tile position currently in view.

Returns

A list of active tiles current in view, sorted by z-index.

Type
Array.<Tily.ActiveTile>

updateTransitions(elapsedTime) → {Tily.utility.vec2}

Update offset and scale transitions.

Inherited From:
Parameters
Name Type Description
elapsedTime number

The time elapsed in seconds since the last draw call.

Returns

The interpolated offset position.

Type
Tily.utility.vec2

zoom(scale, optionsopt)

Zoom the scale with an optional transition animation.

Inherited From:
Parameters
Name Type Attributes Description
scale number

The target scale.

options TransitionOptions <optional>

An optional options object.