BufferBase

Tily. BufferBase

new BufferBase(optionsopt)

Implements basic functionality for buffers and cell buffers.

Parameters
Name Type Attributes Description
options BufferOptions <optional>

An optional options object for configuring the buffer.

Members

activeTiles :Array.<Tily.ActiveTile>

An array of active tiles contained in this buffer.

activeTilesMap :Object

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

canvas :HTMLElement

The canvas element to render this buffer onto.

context :CanvasRenderingContext2D

The canvas context to render onto.

offset :Tily.utility.vec2

A camera offset position for this buffer measured in pixels.

offsetPixels :Tily.utility.vec2

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

(nullable) offsetTransition :Tily.OffsetTransition

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

Default Value:
  • null

options :BufferOptions

Options for configuring this buffer.

scale :number

The number of tiles currently visible along the locked axis.

(nullable) scaleTransition :Tily.ScaleTransition

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

Default Value:
  • null

size :Size

The size of this buffer measured in tiles.

tileSize :number

The side length of each tile measured in pixels.

viewSize :Size

The size of the viewport measured in tiles.

Methods

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

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

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

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

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

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) → {BufferBaseTileInfo}

Get information about the active tiles at a tile position.

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
BufferBaseTileInfo

moveOffset(x, y, optionsopt)

Move the offset with an optional transition animation.

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.

Parameters
Name Type Description
tile Tily.ActiveTile

The tile to remove.

removeAllActiveTiles()

Remove all active tiles from this buffer.

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

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

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.

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.

Parameters
Name Type Attributes Description
scale number

The target scale.

options TransitionOptions <optional>

An optional options object.