Class: Action

Action(actFunction)

A framework for storing a method that is applied to a target Sprite over time.
Actions are typically created with the static methods in the ActionFactory class, added to the target Sprite, and will then be applied automatically.
Actions return true when finished.
Custom Action objects may be created by using inline functions with the necessary parameters, such as:
let teleportRight = new BAGEL.Action(
  function(targetSprite, deltaTime, totalTime)
  {
    targetSprite.moveBy(100, 0);
    return true;
  }
);

Constructor

new Action(actFunction)

This constructor is used by static ActionFactory methods.
Actions store their total running time, as some Actions run only for a precise amount of time.
Parameters:
Name Type Default Description
actFunction function null function that will be applied to the Sprite this Action is attached to; must take parameters (targetSprite, deltaTime, totalTime).
Source:

Methods

apply(targetSprite, deltaTime) → {boolean}

Increments totalTime by deltaTime and applies function to target.
Parameters:
Name Type Description
targetSprite Sprite the sprite to which the function will be applied
deltaTime number elapsed time (seconds) since previous iteration of game loop (typically approximately 1/60 second)
Source:
Returns:
true if the function has completed, false otherwise
Type
boolean

reset()

Sets totalTime to 0, effectively restarting this Action.
Source: