Thread Tools Display Modes
Prev Previous Post   Next Post Next
04/26/14, 02:11 PM   #1
acies
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1
Animating controls

In this tutorial I will show a few examples on how to use the ANIMATION_MANAGER, covering most of the basics.

I'll start off with some of the jargon you'll encounter:
A timeline is a set of animations (not required to be sequential).
Easing is a function applied to the offset for each step in an animation to achieve non-linear transitions. Easing functions are usually made using quadratic or cubic Bezier curves.
Translation refers to the Euclidean transformation of an object's coordinates to a new set of coordinates.

The main types of animations are:
  • ANIMATION_ALPHA
  • ANIMATION_COLOR
  • ANIMATION_SCALE
  • ANIMATION_SCROLL
  • ANIMATION_SIZE
  • ANIMATION_TRANSLATE

The self-explanatory types of directions are:
  • ANIMATION_PLAYBACK_ONE_SHOT (default)
  • ANIMATION_PLAYBACK_LOOP
  • ANIMATION_PLAYBACK_PING_PONG

Let's start with a simple example using CreateSimpleAnimation (single animation):
Lua Code:
  1. function simpleAnimation(control, duration)
  2.     local animation, timeline = CreateSimpleAnimation(ANIMATION_ALPHA, control)
  3.  
  4.     -- start at current alpha
  5.     animation:SetAlphaValues(control:GetAlpha(), 1)
  6.     animation:SetDuration(duration or 1000)
  7.  
  8.     timeline:SetPlaybackType(ANIMATION_PLAYBACK_ONE_SHOT)
  9.     timeline:PlayFromStart()
  10. end

As you will notice, not defining an easing function will simply use linear.
Here's a list of easing functions provided by the API:
  • ZO_BezierInEase
  • ZO_BounceEase
  • ZO_EaseInCubic
  • ZO_EaseInOutCubic
  • ZO_EaseInOutQuadratic
  • ZO_EaseInOutQuartic
  • ZO_EaseInOutQuintic
  • ZO_EaseInQuadratic
  • ZO_EaseInQuartic
  • ZO_EaseInQuintic
  • ZO_EaseOutCubic
  • ZO_EaseOutQuadratic
  • ZO_EaseOutQuartic
  • ZO_EaseOutQuintic
  • ZO_LinearEase (default)
To understand these easing functions, check out http://easings.net/
If you wish to make a custom easing, you can do so with ZO_GenerateCubicBezierEase.
Instead of a tedious trial and error process inputting numbers blindly, I can recommend using this interactive tool to come up with the four numbers required: http://cubic-bezier.com/

Each type of animation has its own method for setting the from and to values.
Here's a more elaborate timeline animation with custom easing:
Lua Code:
  1. -- custom bouncing ("out back") easing
  2. local myEasing = ZO_GenerateCubicBezierEase(.05, 1.85, .75, .75)
  3.  
  4. function timelineAnimation(control)
  5.     local isValidAnchor, point, relativeTo, relativePoint, offsetX, offsetY = control:GetAnchor()
  6.  
  7.     local timeline = ANIMATION_MANAGER:CreateTimeline()
  8.  
  9.     -- scale to 100% using our custom easing
  10.     local popup = timeline:InsertAnimation(ANIMATION_SCALE, control)
  11.     popup:SetScaleValues(0, 1)
  12.     popup:SetDuration(500)
  13.     popup:SetEasingFunction(myEasing)
  14.  
  15.     -- animate opacity from 0% to 100%
  16.     local fadeIn = timeline:InsertAnimation(ANIMATION_ALPHA, control)
  17.     fadeIn:SetAlphaValues(0, 1)
  18.     fadeIn:SetDuration(150)
  19.     fadeIn:SetEasingFunction(ZO_EaseOutQuadratic)
  20.  
  21.     -- begin fading out after 2 seconds
  22.     local fadeOut = timeline:InsertAnimation(ANIMATION_ALPHA, control, 2000)
  23.     fadeOut:SetAlphaValues(1, 0)
  24.     fadeOut:SetDuration(500)
  25.  
  26.     -- begin to slide up after 2 seconds
  27.     local translate = timeline:InsertAnimation(ANIMATION_TRANSLATE, control, 2000)
  28.     translate:SetTranslateOffsets(offsetX, offsetY, offsetX, offsetY - 150)
  29.     translate:SetDuration(500)
  30.     translate:SetEasingFunction(ZO_EaseInQuadratic)
  31.  
  32.  
  33.     -- demonstration of timed callbacks
  34.     timeline:InsertCallback(function()
  35.         d('halfway')
  36.     end, timeline:GetDuration() / 2)
  37.  
  38.     -- reset the control's position once the animation stops
  39.     timeline:SetHandler('OnStop', function()
  40.         d('stopped')
  41.         control:ClearAnchors()
  42.         control:SetAnchor(point, relativeTo, relativePoint, offsetX, offsetY)
  43.     end)
  44.  
  45.     timeline:PlayFromStart()
  46. end

I hope this tutorial clarified some of the less obvious things (cf. http://wiki.esoui.com/Controls)

Last edited by acies : 05/01/14 at 08:07 AM.
  Reply With Quote
 

ESOUI » Developer Discussions » Tutorials & Other Helpful Info » Animating controls


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off