Obsidian API Tutorial #6a – More Animation Events – v0.4.0+

<< PreviousAll tutorials

Let's look at more animation events

Continuing on from the previous tutorial where we set up animation end events, we’re going to look at more animation events. 

Prerequisites

You’ll need an animation event handler setup as per the previous tutorial. 

Start Events

To begin with, there’s the START type. This is the same as the end event, but you guessed it, it’s fired when an animation starts:

@AnimationEventListener(type = AnimationEventType.START)
public void onAnyAnimationStart(AnimationEvent event) {}

Frame Events

It’s possible to listen for events at certain frames, or at every frame. For this we can use the FRAME type. They are registered in the same way, yet you can specify an extra parameter to determine which frame to fire on:

@AnimationEventListener(type = AnimationEventType.FRAME, frame = 3)
public void onThirdFrame(AnimationEvent event) {}

If no frame parameter is provided, the code will be triggered for every frame.

Action Point Events

Listening to frames isn’t that useful since you have to know which frame you want something to occur at, i.e. you have to look at the animation in the animator. However, we can use the ACTION type to listen for action points that have been specified in the animator. Check out this animator tutorial for an explanation of action points. You just need to specify the name of the action point:

@AnimationEventListener(type = AnimationEventType.ACTION, actionName = "Test")
public void onTestAction(AnimationEvent event) {}

Omitting the action point name means the listener will respond to every action point event.

All Events

Finally, if you want to listen to all the animation events, use the ALL type. This will fire for all events regardless of the event type:

@AnimationEventListener(type = AnimationEventType.ALL)
public void onAnyEvent(AnimationEvent event) {}

That should cover everything

I think those types cover every event that’s possible. If not I’ll add more! You can define the entity name and animation name for all types, as explained in the previous tutorial.

<< PreviousAll tutorials