new CellBuffer(optionsopt)
A buffer made out of rectangular cells generated by a cell function, used for infinite scrolling buffers and procedurally generated buffers.
Parameters
Name | Type | Attributes | Description |
---|---|---|---|
options |
CellBufferOptions |
<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:
cellCache :Object
A cache of loaded cells with hashed cell positions as keys and cell instances as values.
context :CanvasRenderingContext2D
The canvas context to render onto.
- Inherited From:
offset :Tily.utility.vec2
A camera offset position for this buffer measured in pixels.
- 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.CellBuffer}
Deserialize the JSON data into a cell buffer. The cell function will need to be re-attached to the resulting cell buffer, as it cannot be serialized.
Parameters
Name | Type | Description |
---|---|---|
s |
string | The JSON data to deserialize. |
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. |
draw(context, elapsedTime, width, height)
Render this buffer's cells 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) → {CellBufferTileInfo}
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. |
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. |
serialize() → {string}
Serialize this cell buffer and return the serialized JSON data. The cell function will not be serialized and will need to be re-attached when the data is deserialized.
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. |