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:
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
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
tileSize :number
The side length of each tile measured in pixels.
- Overrides:
Methods
(static) deserialize(s) → {Tily.Buffer}
Deserialize the JSON data into a buffer.
Parameters
Name | Type | Description |
---|---|---|
s |
string | The JSON data to deserialize. |
(static) fromData(data) → {Tily.Buffer}
Create a buffer from data.
Parameters
Name | Type | Description |
---|---|---|
data |
Object | Serialized buffer data. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |
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. |