View Single Post
05/14/14, 07:00 PM   #5
Roupine
Join Date: May 2014
Posts: 18
If the starting coordinates aren't known, I've found that simply using SetTranslateDeltas() works great.

ie.
Lua Code:
  1. anim:SetTranslateOffsets(originX, originY, originX-100, originY)
  2. -- Is almost the same as:
  3. anim:SetTranslateDeltas(-100, 0)
SetTranslateDeltas() appears to automatically grab the animated control's current X and Y and sets that as the origin point. What this means is, if the control has moved since the deltas were set it will "snap" back. I get around this by calling SetTranslateDeltas() again just before calling the animation if I'm expecting such a case.

For example, if you want the visual effect of controls "bumping up" each other as new ones come in at the bottom of a stack, you can create an animation to translate the control up, then add an "OnStop" handler that will call SetTranslateDeltas() again so the next time that "bump" is called, it will move up from its new position.

Another thing to keep in mind is that the beziers only affect the animation speed, not the translate coordinates. In order to get a curved animation, you can't simply add two translate animations to the same object -- the latter translation overwrites the former. You have to anchor one object to another object and animate each differently.

For example:
Lua Code:
  1. WINDOW_MANAGER:CreateTopLevelWindow("SomeTLW")
  2. ctExample = WINDOW_MANAGER:CreateControl("AnimEx", SomeTLW, CT_CONTROL)
  3. ctExample.lbl = WINDOW_MANAGER:CreateControl("AnimExLabel", ctExample, CT_LABEL)
  4. -- Set Anchors
  5. ctExample:SetAnchor(CENTER,GuiRoot,CENTER)
  6. ctExample.lbl:SetAnchor(CENTER,ctExample,CENTER)
  7. -- Add content to the controls so they're visible
  8. ctExample.lbl:SetFont("ZoFontWinH2")
  9. ctExample.lbl:SetText("Hello, World!")
  10. SomeTLW:SetHidden(false)
  11.  
  12. ctExample.anim = ANIMATION_MANAGER:CreateTimeline()
  13. -- Add the horizontal slide to the Control:
  14. ctExample.anim.slideX = ctExample.anim:InsertAnimation( ANIMATION_TRANSLATE, ctExample, 0 )
  15. ctExample.anim.slideX:SetDuration(500)
  16. ctExample.anim.slideX:SetEasingFunction(ZO_LinearEase)
  17. ctExample.anim.slideX:SetTranslateDeltas(200,0) -- slide right
  18. -- Add the vertical slide to the Label:
  19. ctExample.anim.slideY = ctExample.anim:InsertAnimation( ANIMATION_TRANSLATE, ctExample.lbl, 0 )
  20. ctExample.anim.slideY:SetDuration(500)
  21. ctExample.anim.slideY:SetEasingFunction(ZO_EaseInCubic)
  22. ctExample.anim.slideY:SetTranslateDeltas(0,-200) -- slide up
  23.  
  24. -- Since the animations are part of the same animation timeline,
  25. -- even though they affect two different objects, you only need to call:
  26. ctExample.anim:PlayFromStart()
I only attached the timeline to the control object (ie. ctExample.anim) because this code is adapted from an ObjectPool factory function. It could be any sort of variable that's convenient.


There might be a better method out there, but... I haven't found it.

Last edited by Roupine : 05/14/14 at 09:49 PM. Reason: added example code
  Reply With Quote