-
Notifications
You must be signed in to change notification settings - Fork 125
8. Events and Callbacks
GoKit has a robust amount of events that will reliably fire during the course of a Tween, TweenChain and TweenFlow to give you very strict control over your animations.
The callbacks are as follows:
- onInit
- onBegin
- onIterationStart
- onUpdate
- onIterationEnd
- onComplete
You may set these either on the GoTweenConfig:
GoTweenConfig config = new GoTweenConfig();
config.onBegin(SomeBeginHandler);
or you may set them directly on the Tween:
GoTween moveBlock = Go.to(someGameObject, 1f, config);
moveBlock.setOnCompleteHandler(SomeCompleteHandler);
Since GoKit ensures that the start/end points of each Tween iteration are exactly the properties that you defined, we can ensure that every event will reliably fire through the normal lifespan of a Tween, TweenChan and TweenFlow.
- Called once, before any Tween properties are setup.
Useful it you want to force starting values on your properties right before the Tween starts.
- Called when the Tween is at the start of the timeline.
- Called at the start of an iteration (loop).
- Called every time the tween is updated. (once per frame)
- Called at the end of an iteration (loop).
- Called when the Tween is complete.
When a tween is running indefinitely, this event will never be fired.
Begin/Complete and Start/End events are always relative to the direction that the tween is playing in.
For illustrative purposes, assume this is the visual of a tween that has three loops, with a duration of 1s.
| - - - - - | - - - - - | - - - - - |
t = 0 1 2 3
(a) (b) (c) (d)
If the tween is playing forward:
- onBegin fires at a.
- onIterationStart fires at a, b, c.
- onIterationEnd fires at b, c, d.
- onComplete fires at d.
If the tween is playing in reverse:
- onBegin fires at d.
- onIterationStart fires at b, c, d.
- onIterationEnd fires at a, b, c.
- onComplete fires at a.
All of the aforementioned events will reliably fire when any type of Tween is created and played. If a Tween is being forced to various stages of the timeline via the goto() and gotoAndPlay() methods, there are a few things to keep in mind:
- onBegin will fire if you goto the start of the Tween, relative to its direction.
-
onIterationStart will only fire during a goto() if onBegin will fire.
- Using our example above with the Tween Direction, if you called
someTween.goto(1)
, the onIterationEnd would fire immediately, and the onIterationStart would fire on the following frame.
- Using our example above with the Tween Direction, if you called