ig.

Layer

new Layer()

Layer used to organize entities within game.
- collision checks are handled by layer, i.e. entities cannot collide with entities on another layer.
- pausing game happens on game, layer, and entity levels, and a layer can be set to unpausable. IMPORTANT: for performance, collisions are only checked when something on the layer has changed!

Author:
  • Collin Hover - collinhover.com
Source:

<readonly> _dirtySort :Boolean

Whether layer should be sorted on next update.

Source:

autoSort :Boolean

Whether to automatically sort layer.

Source:

<readonly> changed :Boolean

Whether layer has been changed since last update.

Source:

clearOnLoad :Boolean

Whether to clear layer on load, or should items be persistent across levels.

Default Value:
  • true
Source:
Example
// keep user interface elements across all levels
layerUI.clearOnLoad = false;

ignorePause :Boolean

Whether layer cannot be paused.
- i.e. useful for layers with UI, which should probably not be paused.

Default Value:
  • false
Source:

items :Array

List of layer items. IMPORTANT: items can be instances of any class, as long as they have update and draw methods.

Source:

itemsChecking :Array

List of items that need checks.

Source:

itemsInteractive :Array

List of items that are interactive.

Source:

itemsLight :Array

List of items that are lights.

Source:

itemsOpaque :Array

List of items that cast shadows.

Source:

itemsTargetable :Array

List of items that are targetable.

Source:

name :String

Unique instance name.
- usually names are used to map instances for faster searching.

Source:

noDraw :Boolean

Whether layer can skip draw.

Default Value:
  • false
Source:

noUpdate :Boolean

Whether layer can skip update.

Default Value:
  • false
Source:

numBackgroundMaps :Number

Number of items that are maps.

Source:

numEntities :Number

Number of items that are entities.

Source:

<readonly> paused :Boolean

Whether layer is paused. IMPORTANT: does not guarantee that all items are paused or unpaused!

Source:

preRender :Boolean

Whether layer should automatically prerender background maps.

Source:

sortBy :function

Function to sort by, defaults to game sortBy.

Source:

spatialHash :Object

Spatial hash of all checking items.

Source:

spatialHashCellSize :Number

Spatial hash cell size.

Default Value:
  • 64
Source:

zIndex :Number

Z index for sorting.

Default Value:
  • 0
Source:

addItem(item)

Adds an item to layer immediately. IMPORTANT: use ig.GameExtended#addItem or, if item is an entity, ig.GameExtended#spawnEntity instead for proper deferral.

Parameters:
Name Type Description
item * item with update and draw functions.
Source:

checkEntities()

Checks entities on layer.

Source:

draw()

Draws layer.

Source:

init(name, settings)

Initializes layer.

Parameters:
Name Type Description
name String name of layer
settings Object settings object.
Source:

pause()

Pauses layer.

Source:

ready()

Sets layer as ready.

Source:

removeItem(item)

Removes an item immediately from layer. IMPORTANT: Use ig.GameExtended#removeItem or, if item is an entity, ig.GameExtended#removeEntity instead for proper deferral.

Parameters:
Name Type Description
item * item to be removed.
Source:

reset()

Resets layer.

Source:

sort()

Flags layer for item sorting.

Source:

unpause()

Unpauses layer.

Source:

update()

Updates layer and all items.

Source: