Showing code for

States

Show one child at a time, for things like idle, win and lose screens.

What zStudio needs

Set the container type to State. Only one child shows at a time, and it starts on the child named idle, or the first child if there is none.

character (State)
├─ idle
├─ run
└─ jump

Use it

const character = stage.get('character') as ZState;

character.setState('run');

character.getCurrentState()?.name; // 'run'
character.hasState('jump');        // true
character.getAllStateNames();      // all child names

A name that doesn't exist falls back to idle with no error, so check your spelling if the wrong state appears. Timelines inside a state stop when it hides and restart when it shows, unless you turned off play on start.