API Documentation for: 0.11.8
Show:

platypus.components.HandlerLogic Class

A component that handles updating logic components. Each tick it calls all the entities that accept 'handle-logic' messages. This component is usually used on an "action-layer".

Methods

'camera-update'

(
  • camera
)

Defined in 'camera-update':193

Changes the active logic area when the camera location changes.

Parameters:

'child-entity-added'

(
  • entity
)

Called when a new entity has been added and should be considered for addition to the handler. If the entity has a 'handle-logic' message id it's added to the list of entities.

Parameters:

  • entity platypus.Entity

    The entity that is being considered for addition to the handler.

'child-entity-removed'

(
  • entity
)

Called when an entity should be removed from the list of logically updated entities.

Parameters:

'pause-logic'

(
  • [options]
)

Defined in 'pause-logic':151

When this event is triggered, handle-logic messages cease to be triggered on each tick.

Parameters:

  • [options] Object optional
    • [time] Number optional

      If set, this will pause the logic for this number of milliseconds. If not set, logic is paused until an unpause-logic message is triggered.

'tick'

(
  • tick
)

Defined in 'tick':215

Sends a 'handle-logic' message to all the entities the component is handling. If an entity does not handle the message, it's removed it from the entity list.

Parameters:

  • tick Object

    Tick information that is passed on to children entities via "handle-logic" events.

    • delta Number

      The time passed since the last tick.

'unpause-logic'

()

Defined in 'unpause-logic':175

When this event is triggered, handle-logic messages begin firing each tick.

addEventListener

(
  • event
  • callback
)
Function private
This method adds an event listener to the entity.

Parameters:

  • event String
    The event that this component should listen for.
  • callback Function
    The handler for the event.

Returns:

Function: handler A reference to the bound handler.

addMethod

(
  • name
  • func
)
private
This method adds a method to the entity.

Parameters:

  • name String
    The name of the method. For example, if name is "turnYellow", the method is accessible on the entity as entity.turnYellow().
  • func Function
    The function describing the method.

destroy

() private

Inherited from platypus.Component: destroy:54

This method cleans up listeners and methods that this component added to the entity. It should never be called by the component itself. Call this.owner.removeComponent(this) instead.

getAssetList

(
  • definition
  • properties
  • defaultProperties
)
Array
This method can be overwritten to provide the list of assets this component requires. This method is invoked when the list of game scenes is created to determine assets for each scene.

Parameters:

  • definition Object
    The definition for the component.
  • properties Object
    The properties of the Entity.
  • defaultProperties Object
    The default properties of the Entity.

Returns:

Array: A list of the necessary assets to load.

getLateAssetList

(
  • data
)
Array
This method can be overwritten to provide the list of assets this component requires. This method is invoked when the list of game scenes is created to determine assets for each scene.

Parameters:

  • data Object
    Scene data that affects the list of assets.

Returns:

Array: A list of the necessary assets to load.

removeEventListener

(
  • event
  • callback
)
private
This method removes an event listener from the entity.

Parameters:

  • event String
    The event for which to remove a listener.
  • callback Function
    The listener to remove. If not supplied, all event listeners for the provided event are removed.

removeEventListeners

(
  • [listeners]
)
private
This method removes multiple event listeners from the entity.

Parameters:

  • [listeners] Array optional
    The list of listeners to remove. If not supplied, all event listeners are removed.

removeMethod

(
  • name
)
private
This method removes a method from the entity.

Parameters:

  • name String
    The name of the method to be removed.

toJSON

() Object

Inherited from platypus.Component: toJSON:45

Available since 0.11.0

Returns a JSON object describing the component.

Returns:

Object: Returns a JSON definition that can be used to recreate the component.

toString

() String
Returns a string describing the component.

Returns:

String: Returns the component type as a string of the form "[Component ComponentType]".

Properties

alwaysOn

Boolean

Defined in alwaysOn:43

Available since 0.7.1

Whether logic should always run on all entities or only run on entities within the visible camera area (plus the buffer amount specified by the buffer property).

Default: false

buffer

Number

Defined in buffer:54

The buffer area around the camera in which entity logic is active. This property is available on the Entity as entity.buffer.

Default: camera width / 10

maxStepsPerTick

Number

Defined in maxStepsPerTick:72

The maximum number of steps to take for a given tick, to prevent lag overflow.

Default: 100

stepLength

Number

Defined in stepLength:63

The length in milliseconds of a single logic step. If the framerate drops too low, logic is run for each step of this many milliseconds. This property is available on the Entity as entity.stepLength.

Default: 5

timeMultiplier

Number

Defined in timeMultiplier:81

Available since 0.7.1

Whether logic should occur at an alternate speed. This is useful for simulations where the game should speed up or slow down.

Default: 1

Events

'check-collision-group'

This event is triggered on the entity (layer) to test collisions once logic has been completed.

Event Payload:

  • tick Object
    • delta Number

      The time that has passed since the last tick.

    • camera Null | platypus.AABB

      The range of the logic camera area. This is typically larger than the visible camera. This value is null if alwaysOn is set to true on this component.

    • entities Array

      This is a list of all the logically active entities.

'handle-logic'

Defined in 'handle-logic':297

This event is triggered on children entities to run their logic.

Event Payload:

  • tick Object
    • delta Number

      The time that has passed since the last tick.

    • camera Null | platypus.AABB

      The range of the logic camera area. This is typically larger than the visible camera. This value is null if alwaysOn is set to true on this component.

    • entities Array

      This is a list of all the logically active entities.

'handle-movement'

Defined in 'handle-movement':308

Available since 0.6.8

This event is triggered on children entities to move. This happens immediately after logic so entity logic can determine movement.

Event Payload:

  • tick Object
    • delta Number

      The time that has passed since the last tick.

    • camera Null | platypus.AABB

      The range of the logic camera area. This is typically larger than the visible camera. This value is null if alwaysOn is set to true on this component.

    • entities Array

      This is a list of all the logically active entities.

'handle-post-collision-logic'

This event is triggered on entities to run logic that may depend upon collision responses.

Event Payload:

  • tick Object
    • delta Number

      The time that has passed since the last tick.

    • camera Null | platypus.AABB

      The range of the logic camera area. This is typically larger than the visible camera. This value is null if alwaysOn is set to true on this component.

    • entities Array

      This is a list of all the logically active entities.

'logic-paused'

Defined in 'logic-paused':165

Available since 0.8.4

Notifies children entities that logic has been paused.

'logic-tick'

Defined in 'logic-tick':266

Available since 0.8.1

This event is triggered on the top-level layer to signify a "handle-logic" event is about to be triggered on children. This is unique from the layer's "tick" event in that it occurs the same number of times as the "handle-logic" event and will not occur if HandlerLogic is paused.

Event Payload:

  • tick.delta Number

    The time that has passed since the last tick.

  • tick.camera Null | platypus.AABB

    The range of the logic camera area. This is typically larger than the visible camera. This value is null if alwaysOn is set to true on this component.

  • tick.entities Array

    This is a list of all the logically active entities.

'logic-unpaused'

Defined in 'logic-unpaused':183

Available since 0.8.4

Notifies children entities that logic has been unpaused.

'prepare-logic'

Defined in 'prepare-logic':285

Available since 0.6.8

This event is triggered on children entities to run anything that should occur before "handle-logic". For example, removing or adding components should happen here and not in "handle-logic".

Event Payload:

  • tick Object
    • delta Number

      The time that has passed since the last tick.

    • camera Null | platypus.AABB

      The range of the logic camera area. This is typically larger than the visible camera. This value is null if alwaysOn is set to true on this component.

    • entities Array

      This is a list of all the logically active entities.

'state-changed'

Defined in 'state-changed':355

Triggered on entities when the entity's state has been changed.

Event Payload:

  • state Object

    A list of key/value pairs representing the owner's state (this value equals entity.state).