TileLayer

TileLayer

LittleJS Tile Layer System
- Caches arrays of tiles to offscreen canvas for fast rendering
- Unlimted numbers of layers, allocates canvases as needed
- Interfaces with EngineObject for collision
- Collision layer is separate from visible layers
- Tile layers can be drawn to using their context with canvas2d
- It is recommended to have a visible layer that matches the collision

Methods

# (static) getTileCollisionData(pos) → {Number}

Get tile collision data
Parameters:
Name Type Description
pos Vector2
Returns:
Type
Number

# (static) initTileCollision(size)

Clear and initialize tile collision
Parameters:
Name Type Description
size Vector2

# (static) setTileCollisionData(pos, dataopt)

Set tile collision data
Parameters:
Name Type Attributes Default Description
pos Vector2
data Number <optional>
0

# (static) tileCollisionRaycast(posStart, posEnd, objectopt) → {Vector2}

Return the center of tile if any that is hit (this does not return the exact hit point)
Parameters:
Name Type Attributes Description
posStart Vector2
posEnd Vector2
object EngineObject <optional>
Returns:
Type
Vector2

# (static) tileCollisionTest(pos, sizeopt, objectopt) → {Boolean}

Check if collision with another object should occur
Parameters:
Name Type Attributes Default Description
pos Vector2
size Vector2 <optional>
new Vector2(1,1)
object EngineObject <optional>
Returns:
Type
Boolean

# destroy()

Destroy this tile layer

# drawAllTileData()

Draw all the tiles in this layer

# drawCanvas2D(pos, size, angle, mirror, drawFunction)

Draw directly to the 2d canvas in world space (bipass webgl)
Parameters:
Name Type Description
pos Vector2
size Vector2
angle Number
mirror Boolean
drawFunction function

# drawRect(pos, sizeopt, coloropt, angleopt)

Draw a rectangle directly onto the layer canvas
Parameters:
Name Type Attributes Default Description
pos Vector2
size Vector2 <optional>
new Vector2(1,1)
color Color <optional>
new Color(1,1,1)
angle Number <optional>
0

# drawTile(pos, sizeopt, tileIndexopt, tileSizeopt, coloropt, angleopt, mirroropt)

Draw a tile directly onto the layer canvas
Parameters:
Name Type Attributes Default Description
pos Vector2
size Vector2 <optional>
new Vector2(1,1)
tileIndex Number <optional>
-1
tileSize Vector2 <optional>
defaultTileSize
color Color <optional>
new Color(1,1,1)
angle Number <optional>
0
mirror Boolean <optional>
0

# drawTileData(layerPos)

Draw the tile at a given position
Parameters:
Name Type Description
layerPos Vector2

# getData(layerPos) → {TileLayerData}

Get data at a given position in the array
Parameters:
Name Type Description
layerPos Vector2 Local position in array
Returns:
Type
TileLayerData

# redraw()

Draw all the tile data to an offscreen canvas using webgl if possible

# redrawEnd()

Call to end the redraw process

# redrawStart(clearopt)

Call to start the redraw process
Parameters:
Name Type Attributes Default Description
clear Boolean <optional>
1 Should it clear the canvas before drawing

# setData(position, data, redrawopt)

Set data at a given position in the array
Parameters:
Name Type Attributes Default Description
position Vector2 Local position in array
data TileLayerData Data to set
redraw Boolean <optional>
0 Force the tile to redraw if true