Events

An event is a trigger for something to happen during an animation. For example, for a sound to play when a characters feet hit the ground. Events aren't limited to audio, they can be used to run any code you like at runtime. For example, to spawn particle effects, open a door, hurt an enemy, manipulate the skeleton via code, etc.

Setup

An event is created by selecting the Events node in the tree and clicking New Event.

Once the event is given a meaningful name, it shows up in the tree. An event has three properties: integer, float, and string.

These properties allow an extra bit of information to be specified for the event. They can optionally be given a default value while in Setup Mode.

Keying

To trigger an event during an animation:

  1. Ensure you are in Animate Mode.
  2. Move the timeline to the desired position.
  3. Optionally set the event's properties in the tree.
  4. Click the key button next to the event in the tree.

When the animation plays or the timeline is scrubbed forward, the event will trigger. This is indicated by the event name appearing above the skeleton in the editor area.

Responding to events

How you setup your event names and values is entirely up to you, as is what happens when the events trigger. Events don't actually perform any action by themselves. You need to write code in your application that is triggered when an event occurs and takes the appropriate action. Typically this is done by setting a callback on AnimationState:

AnimationState state = ...
state.addListener(new AnimationStateAdapter() {
   public void event (int trackIndex, Event event) {
      // Inspect and respond to the event here.
      if (event.name == "footstep")
         Audio.play("footstep" + event.intValue + ".wav");
   }
});

A callback can also be set on an individual TrackEntry:

TrackEntry entry = state.setAnimation(0, "run", true);
entry.setListener(new AnimationStateAdapter() {
   public void event (int trackIndex, Event event) {
      // Inspect and respond to the event here.
      if (event.name == "audio")
         Audio.play(event.stringValue);
   }
});

Video

Next: Constraints Previous: Skins