View Single Post
09/15/14, 04:43 AM   #2
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Atropos View Post
Hey folks, I'd like to put a bounty out for a simple tutorial on using the ESO AnimationManager and/or AnimationObjects. If anyone is familiar with these functions, I would love to see a brief code snippet that explains the how to instantiate an animation object, associate it with a control, and fire the animation.

For example, maybe a quick how-to on transitioning the alpha of control from 0 to 1 over a 2 second duration?

This would be really helpful if anyone understands it enough to share some tricks!
A while back acies sent this information:
http://www.esoui.com/forums/showthread.php?t=1191

I use a simple alpha animation in Bloody Screen addon, but I do not use AnimationManager directly, I'm using ZO_AlphaAnimation object.

Lua Code:
  1. ZO_AlphaAnimation:New(animatedControl)
  2. ZO_AlphaAnimation:GetControl()
  3. ZO_AlphaAnimation:FadeIn(delay, duration, fadeOption, callback, shownOption)
  4. ZO_AlphaAnimation:FadeOut(delay, duration, fadeOption, callback, shownOption)
  5. ZO_AlphaAnimation:PingPong(initialAlpha, finalAlpha, duration, loopCount, callback)
  6. ZO_AlphaAnimation:SetPlaybackLoopsRemaining(loopCount)
  7. ZO_AlphaAnimation:IsPlaying()
  8. ZO_AlphaAnimation:SetMinMaxAlpha(minAlpha, maxAlpha)
  9. ZO_AlphaAnimation:Stop(stopOption)

Code:
Arguments:
delay, duration - milliseconds
fadeOption - ZO_ALPHA_ANIMATION_OPTION_USE_CURRENT_ALPHA or ZO_ALPHA_ANIMATION_OPTION_FORCE_ALPHA
callback - function which will be called when animation finishes
showOption - ZO_ALPHA_ANIMATION_OPTION_USE_CURRENT_SHOWN or ZO_ALPHA_ANIMATION_OPTION_FORCE_SHOWN
stopOption - ZO_ALPHA_ANIMATION_OPTION_PREVENT_CALLBACK or nil
A small example:
Lua Code:
  1. local tlw, texture, animation
  2.  
  3. local function OnMouseUp(self, button, upInside)
  4.    local currentAlpha = control:GetAlpha()
  5.    local delay = 0         -- milliseconds before animation starts
  6.    local duration = 2000   -- milliseconds for full animation. Actual duration will be duration * currentAlpha.
  7.    local fadeOption = ZO_ALPHA_ANIMATION_OPTION_USE_CURRENT_ALPHA
  8.    local callback          -- I will leave callback nil, it is function which will be called when animation finishes
  9.    local showOption = ZO_ALPHA_ANIMATION_OPTION_USE_CURRENT_SHOWN
  10.  
  11.    if currentAlpha < 0.5 then
  12.       animation:FadeIn(delay, duration, fadeOption, callback, shownOption)
  13.    else
  14.       animation:FadeOut(delay, duration, fadeOption, callback, shownOption)
  15.    end
  16. end
  17.  
  18. tlw = WINDOW_MANAGER:CreateTopLevelWindow()
  19. tlw:SetDimensions(128,128)
  20. tlw:SetAnchor(CENTER, GuiRoot, CENTER, 0, 0)
  21. tlw:SetHandler("OnMouseUp", OnMouseUp)
  22. tlw:SetMouseEnabled(true)
  23. tlw:SetAlpha(1)
  24. tlw:SetHidden(false)
  25. texture = WINDOW_MANAGER:CreateControl(nil, tlw, CT_TEXTURE)
  26. texture:SetTexture("/esoui/art/icons/poi/poi_groupboss_complete.dds")
  27. texture:SetAnchorFill(tlw)
  28. animation = ZO_AlphaAnimation:New(tlw)
(I didn't test this code, so there could be some typos)

Last edited by Garkin : 09/15/14 at 05:30 AM.
  Reply With Quote