Skip to main content

Class: abstract Action

The Action class has static methods for creating actions to be executed by an M2Node.

Extended by

Constructors

new Action()

new Action(runDuringTransition): Action

Parameters

runDuringTransition: boolean= false

Returns

Action

Source

Action.ts:43

Properties

_completed

private _completed: boolean = false

Source

Action.ts:32


duration

duration: Futurable

Source

Action.ts:38


key?

optional key: string

Source

Action.ts:41


parent?

optional parent: ActionContainer

Source

Action.ts:40


runDuringTransition

runDuringTransition: boolean

Source

Action.ts:39


runStartTime

runStartTime: number = -1

Start time of a running action is always known; it is not a Futurable. -1 indicates that the root action has not yet started running.

Source

Action.ts:37


running

running: boolean = false

Source

Action.ts:31


startOffset

startOffset: Futurable

Source

Action.ts:29


started

started: boolean = false

Source

Action.ts:30


type

abstract type: ActionType

Source

Action.ts:28

Accessors

completed

get completed(): boolean

Indicates whether the action has completed.

set completed(value): void

Parameters

value: boolean

Returns

boolean

Source

Action.ts:940

Methods

assignDurations()

private assignDurations(action): void

Assigns durations to all actions in the hierarchy.

Parameters

action: Action

the action to assign durations to

Returns

void

Remarks

Uses recursion to handle arbitrary level of nesting parent actions within parent actions.

Source

Action.ts:149


assignParents()

private assignParents(action, rootAction, key?): void

Parses the action hierarchy and assigns each action its parent and root action.

Parameters

action: Action

the action to assign parents to

rootAction: Action

top-level action passed to the run method

key?: string

optional string to identify an action. The key is assigned to every action in the hierarchy.

Returns

void

Remarks

Uses recursion to handle arbitrary level of nesting parent actions within parent actions. When this method is called from the initialize() method, the root action is both the action and the rootAction. This is because the action is the top-level action in the hierarchy. When the method calls itself recursively, the rootAction remains the same, but the action is a child action or the action of a repeating action.

Source

Action.ts:96


assignRunStartTimes()

assignRunStartTimes(action, runStartTime): void

Assigns RunStartTime to all actions in the hierarchy.

Parameters

action: Action

the action to assign RunStartTime to

runStartTime: number

Returns

void

Remarks

Uses recursion to handle arbitrary level of nesting parent actions within parent actions.

Source

Action.ts:647


assignStartOffsets()

private assignStartOffsets(action): void

Assigns start offsets to all actions in the hierarchy.

Parameters

action: Action

the action to assign start offsets to

Returns

void

Remarks

Uses recursion to handle arbitrary level of nesting parent actions within parent actions.

Source

Action.ts:222


calculateDuration()

private calculateDuration(action): Futurable

Calculates the duration of an action, including any children actions the action may contain.

Parameters

action: Action

Returns

Futurable

the calculated duration

Remarks

Uses recursion to handle arbitrary level of nesting parent actions within parent actions

Source

Action.ts:166


calculateStartOffset()

private calculateStartOffset(action): Futurable

Calculates the start offset. This is when an action should start, relative to the start time of its parent (if it has a parent).

Parameters

action: Action

the action to calculate the start offset for

Returns

Futurable

the start offset as a Futurable

Source

Action.ts:236


clone()

abstract clone(): Action

Clones the action, and any actions it contains, recursively.

Returns

Action

a clone of the action

Remarks

We need to clone an action before running it because actions have state that is updated over time such as whether they are running or not, etc. If we didn't clone actions, two nodes reusing the same action would share state. On Action, this method is abstract and is implemented in each subclass.

Source

Action.ts:77


initialize()

initialize(key?): Action

Prepares the Action for evaluation.

Parameters

key?: string

optional string to identify an action

Returns

Action

action prepared for evaluation

Remarks

Calculates start times for all actions in the hierarchy and returns a copy of the action that is prepared for evaluation during the update loop.

Source

Action.ts:57


isParent()

isParent(action): action is ActionContainer

Type guard that returns true if the action is a parent action.

Parameters

action: Action

action to check

Returns

action is ActionContainer

true if the action is a parent action

Remarks

Parent actions are Group, Sequence, Repeat, and RepeatForever actions.

Source

Action.ts:910


isRepeating()

private isRepeating(action): action is RepeatingActionContainer

Type guard that returns true if the action can repeat.

Parameters

action: Action

action to check

Returns

action is RepeatingActionContainer

true if the action is a RepeatAction or RepeatForeverAction

Remarks

Repeating actions are Repeat and RepeatForever actions.

Source

Action.ts:927


propagateRunDuringTransition()

private propagateRunDuringTransition(action): void

Sets the runDuringTransition property based on descendants.

Parameters

action: Action

to propagate runDuringTransition property to

Returns

void

Remarks

This ensures that a parent action has its runDuringTransition property set to true if any of its descendants have their runDuringTransition property set to true. Parent actions do not have a way for the user to set this property directly; it is inferred (propagated up) from the descendants.

Source

Action.ts:130


restartAction()

restartAction(action, now): void

Configures action to be run again.

Parameters

action: Action

action to restart

now: number

current time

Returns

void

Remarks

This method is called on a repeating action's children when they need to be run again.

Source

Action.ts:665


shouldBeRunning()

shouldBeRunning(now): boolean

Determines if the action should be running.

Parameters

now: number

current time

Returns

boolean

true if the action should be running

Remarks

An action should be running if current time is in the interval [ start time + start offset, start time + start offset + duration ]

Source

Action.ts:704


custom()

static custom(options): CustomAction

Creates an action that will execute a callback function.

Parameters

options: CustomActionOptions

CustomActionOptions

Returns

CustomAction

The custom action

Source

Action.ts:746


evaluateAction()

static evaluateAction(action, node, now, dt): void

Evaluates an action, updating the node's properties as needed.

Parameters

action: Action

the Action to be evaluated and possibly run

node: M2Node

the M2Node that the action will be run on

now: number

the current elapsed time, from performance.now()

dt: number

the time since the last frame (delta time)

Returns

void

Remarks

This method is called every frame by the M2Node's update() method.

Source

Action.ts:279


evaluateCustomAction()

static private evaluateCustomAction(action): void

Parameters

action: Action

Returns

void

Source

Action.ts:632


evaluateFadeAlphaAction()

static private evaluateFadeAlphaAction(action, node, elapsed, dt): void

Parameters

action: Action

node: M2Node

elapsed: number

dt: number

Returns

void

Source

Action.ts:488


evaluateMoveAction()

static private evaluateMoveAction(action, node, elapsed): void

Parameters

action: Action

node: M2Node

elapsed: number

Returns

void

Source

Action.ts:535


evaluatePlayAction()

static private evaluatePlayAction(node, action): void

Parameters

node: M2Node

action: Action

Returns

void

Source

Action.ts:582


evaluateRepeatingActions()

static private evaluateRepeatingActions(action, now): void

Parameters

action: RepeatingActionContainer

now: number

Returns

void

Source

Action.ts:389


evaluateRotateAction()

static private evaluateRotateAction(action, node, elapsed, dt): void

Parameters

action: Action

node: M2Node

elapsed: number

dt: number

Returns

void

Source

Action.ts:431


evaluateScaleAction()

static private evaluateScaleAction(action, node, elapsed, dt): void

Parameters

action: Action

node: M2Node

elapsed: number

dt: number

Returns

void

Source

Action.ts:512


evaluateWaitAction()

static private evaluateWaitAction(action, now): void

Parameters

action: Action

now: number

Returns

void

Source

Action.ts:571


fadeAlpha()

static fadeAlpha(options): FadeAlphaAction

Creates an action that will change the node's alpha (opacity).

Parameters

options: FadeAlphaActionOptions

FadeAlphaActionOptions

Returns

FadeAlphaAction

The fadeAlpha action

Remarks

Alpha has multiplicative inheritance. For example, if the node's parent is alpha .5 and this node's action fades alpha to .4, then the node will appear with alpha .2.

Source

Action.ts:795


group()

static group(actions): GroupAction

Create an array of actions that will be run simultaneously.

Parameters

actions: Action[]

One or more actions that form the group

Returns

GroupAction

Remarks

All actions within the group will begin to run at the same time. The group will be considered completed when the longest-running action has completed.

Source

Action.ts:868


move()

static move(options): MoveAction

Creates an action that will move a node to a point on the screen.

Parameters

options: MoveActionOptions

MoveActionOptions

Returns

MoveAction

The move action

Source

Action.ts:717


play()

static play(options?): PlayAction

Creates an action that will play a sound.

Parameters

options?: PlayActionOptions

PlayActionOptions

Returns

PlayAction

The play action

Remarks

This action can only be used with a SoundPlayer node. It will throw an error if used with any other node type.

Source

Action.ts:762


repeat()

static repeat(options): RepeatAction

Creates an action that will repeat another action a given number of times.

Parameters

options: RepeatActionOptions

RepeatActionOptions

Returns

RepeatAction

The repeat action

Source

Action.ts:880


repeatForever()

static repeatForever(options): RepeatForeverAction

Creates an action that will repeat another action forever.

Parameters

options: RepeatForeverActionOptions

RepeatForeverActionOptions

Returns

RepeatForeverAction

The repeat forever action

Remarks

A repeat forever action is a special case of a repeat action where the count is set to infinity.

Source

Action.ts:897


rotate()

static rotate(options): RotateAction

Creates an action that will rotate the node.

Parameters

options: RotateActionOptions

RotateActionOptions

Returns

RotateAction

The rotate action

Remarks

Rotate actions are applied to their children. In addition to this node's rotate action, all ancestors' rotate actions will also be applied.

Source

Action.ts:812


scale()

static scale(options): ScaleAction

Creates an action that will scale the node's size.

Parameters

options: ScaleActionOptions

ScaleActionOptions

Returns

ScaleAction

The scale action

Remarks

Scaling is relative to any inherited scaling, which is multiplicative. For example, if the node's parent is scaled to 2.0 and this node's action scales to 3.0, then the node will appear 6 times as large as original.

Source

Action.ts:777


sequence()

static sequence(actions): SequenceAction

Creates an array of actions that will be run in order.

Parameters

actions: Action[]

One or more actions that form the sequence

Returns

SequenceAction

Remarks

The next action will not begin until the current one has finished. The sequence will be considered completed when the last action has completed.

Source

Action.ts:852


wait()

static wait(options): WaitAction

Creates an action that will wait a given duration before it is considered complete.

Parameters

options: WaitActionOptions

WaitActionOptions

Returns

WaitAction

The wait action

Source

Action.ts:733