Skip to content

Activating States

You may activate a state from within the Mattercraft visual editor, or with custom scripts.

For more information about adding interactivity to your Mattercraft projects, consider reading our Adding interactivity article.

Activating a state with the Toggle Layer Clips Behavior Action

You can activate a state by using the following instructions:

  1. Find the Node you wish to activate the State with inside the Hierarchy Panel and select it
  2. Head to the Behavior Actions Panel and click on the + (plus) icon
  3. Find the Animation Actions category and use any of the following Behavior actions to activate the State:

Behavior action Description
Toggle Layer Clips Toggle between two layer clips. Useful for turning states ‘on’ or ‘off’ with one node.
Set Layer Off Resets the chosen layer to the values specified by the Off state.
Play Layer Clip Activates a chosen state.
Activate State Activates a chosen state and presents the stored values.

To activate a state with script, it must be in a layer. You can then locate a specific state clip and use the following function to control it:

Function Description
.play() Activates a chosen state and presents the stored values.

An example custom behavior for activating a state might look like this:

@zRegister('onPointerDown')
private _handlePointerDown() {
this.zcomponent.animation.layers.myLayer.clips.myState.play();
}

See Mattercraft’s full API documentation here.