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 States with Behavior actions

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.

Activating States with Script

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:

// Register that this node should be listening to an event,
// in this case onPointerDown (on click or tap)
this.register(this.instance.onPointerDown, evt => {

    // Activate the state by finding the layer containing the
    // state clip; and then the state itself
    this.zcomponent.animation.layers.myLayer.clips.myState.play();

});
zapcode branded_zapcode i