ActionState

platypus. ActionState

new ActionState(event, states, trigger) → {ActionState}

This class defines an action state based on one or more inputs. This is used by EntityController to produce event messages listing whether a particular action is "triggered", "pressed", and/or "released".

Source:
Parameters:
Name Type Description
event String

The name of the event to trigger on the Entity.

states Object

A list of key/value pairs describing what states should be true or false on the Entity for this action to be triggered.

trigger function

The function to be called if one or more inputs are active and the current state of the Entity is valid.

Returns:
Type:
ActionState

Returns the new ActionState object.

Methods

(static) recycle(actionState)

Returns an ActionState back to the cache. Prefer the ActionState's recycle method since it recycles property objects as well.

Source:
Parameters:
Name Type Description
actionState platypus.ActionState

The ActionState to be recycled.

(static) setUp() → {platypus.ActionState}

Returns an ActionState from cache or creates a new one if none are available.

Source:
Returns:
Type:
platypus.ActionState

The instantiated ActionState.

recycle()

Relinquishes properties of the ActionState and recycles it.

Source:

resolve()

Triggers events on the Entity related to the ActionState's state. This is necessarily separate from the update method since triggered events could affect entity state. The messages have the following form and are only triggered if one of the values is true:

{
    "triggered": true,
    "pressed": true,
    "released": false
}

Here is a mapping of the various event messages depending on the ActionState's state.

ActionState State:
     wasValid:  0 0 0 0  0 0 0 0  1 1 1 1  1 1 1 1
        valid:  0 0 0 0  1 1 1 1  0 0 0 0  1 1 1 1
    wasActive:  0 0 1 1  0 0 1 1  0 0 1 1  0 0 1 1
       active:  0 1 0 1  0 1 0 1  0 1 0 1  0 1 0 1
Events:
    triggered:  0 0 0 0  0 1 0 0  0 0 0 0  0 1 0 0
      pressed:  0 0 0 0  0 1 0 1  0 0 0 0  0 1 0 1
     released:  0 0 0 0  0 0 1 0  0 0 1 1  0 0 1 0
Source:

update(state) → {Boolean}

Updates the state of the action by checking the state of the Entity and whether any inputs are active.

Source:
Parameters:
Name Type Description
state Object

The Entity's state property to compare against the ActionState's valid state.

Returns:
Type:
Boolean

Whether the ActionState is triggered, pressed, or released.