Elitist Jerks
Register
Blogs
Forums


Go Back   Elitist Jerks » Blogs » Zorks interface blog

Me blogging about random interface topics.
Rate this Entry

Make textures rotate without the need of onUpdate

Posted 10/26/09 at 5:08 AM by zork
Updated 10/26/09 at 9:08 AM by zork
I recently learned a bit more about the animation system from Blizzard that is imo way to underused by most addon authors.

Maybe it's just because the have no clue that it exists or maybe they are not capable of doing (which I doubt). I think its laziness. In my opinion the reward of getting into it will be worth it.

I'm using the new animation system from Blizzard at the minimap and for the orbs. You can create really cool stuff without major texture spam. Some basic textures are all you need.

To make a rotation-animation work without any onUpdate this is what you are looking for:
Code:
AnimationGroup:SetLooping("REPEAT")
For more read: SetLooping

Once "played" the animationgroup will always repeat itself, so no onUpdate needed to start it again.

Quote:
The only big package that I am aware of that currently has some animationgroup functions is OpenRDX.
List of OpenRDX animation files: OpenRDX SVN
Example

Now: Let us do a quick animationgroup example for a texture rotation.

First we need a frame to work with.

Code:
local h = CreateFrame("Frame",nil,UIParent)
So now "h" is our frame. Now let us apply some values to the frame:
Code:
h:SetHeight(200)
h:SetWidth(200)             
h:SetPoint("CENTER",0,0) --will be in the center of your screen (anchorframe is UIParent)
h:SetScale(1)
h:SetFrameLevel(0) --to over-/underlay other textures/frames
Our (h)olderframe for our texture is done. Currently it is empty. So let us apply a texture now.

Code:
local t = h:CreateTexture()
So, "t" is now our texture object. Llet us give it some values now.
Code:
t:SetAllPoints(h)
local texturepath = "Interface\\AddOns\\PathToMyTexture\\MyTexture"
t:SetTexture(texturepath)
t:SetBlendMode("BLEND") --choose "blend" for normal color or "add" to multiply the texture with the background
t:SetVertexColor(1,0,0,1) --red color, full alpha
The texture object is done. When finished we want to return the (h)olderframe out of a function. If you want to have access to the texture aswell we need to create a subobject for "h" that will be our texture. Thus:
Code:
h.t = t --h.t will contain our texture object
Now we need to create the animationgroup:
Code:
local ag = h:CreateAnimationGroup()
h.ag = ag --new subobject of h which will be our animationgroup
For more read: AnimationGroup

So, now we have the animationgroup-container ready to be filled with animations. Those can be rotations (rotating textures), translations (moving a texture from one point on the screen to another), scaling- and alpha-changes.

Let us add a rotation animation now:
Code:
local a1 = h.ag:CreateAnimation("Rotation")
a1:SetDegrees(-360) -- -360° = clockwise, 360° = counter-clockwise
a1:SetDuration(60) --how long should it take to make rotate the texture for the degrees set in seconds?
h.ag.a1 = a1 --new subobject that will contain our animation
For more read: CreateAnimation

Finished. We now have the holderframe that containts the texture and the animations set. Time to "play()" it.
Code:
h.ag:Play()
h.ag:SetLooping("REPEAT") --This will tell the animationgroup to repeat itself until stopped or a new looping is defined
If we put everything we just wrote into a function the final result would look like:

Code:
local function my_animationgroup_test()

  local h = CreateFrame("Frame",nil,UIParent)
  h:SetHeight(200)
  h:SetWidth(200)             
  h:SetPoint("CENTER",0,0) --will be in the center of your screen (anchorframe is UIParent)
  h:SetScale(1)
  h:SetFrameLevel(0) --to over-/underlay other textures/frames
  
  local t = h:CreateTexture()
  t:SetAllPoints(h)
  local texturepath = "Interface\\AddOns\\PathToMyTexture\\MyTexture"
  t:SetTexture(texturepath)
  t:SetBlendMode("BLEND") --choose "blend" for normal color or "add" to multiply the texture with the background
  t:SetVertexColor(1,0,0,1) --red color, full alpha
  h.t = t --h.t will contain our texture object
  
  local ag = h:CreateAnimationGroup()
  h.ag = ag --new subobject of h which will be our animationgroup
  
  local a1 = h.ag:CreateAnimation("Rotation")
  a1:SetDegrees(-360) -- -360° = clockwise, 360° = counter-clockwise
  a1:SetDuration(60) --how long should it take to make rotate the texture for the degrees set in seconds?
  h.ag.a1 = a1 --new subobject that will contain our animation
  
  h.ag:Play()
  h.ag:SetLooping("REPEAT") --This will tell the animationgroup to repeat itself until stopped or a new looping is defined
  
  return h

end

local f = my_animationgroup_test() --f will contain your frame with the animation now
If you want to know how this could be used ingame check: Galaxy animation, it shows some rotating textures.

The range of applications that are possible is quite huge. You can animate textstrings, textures and much more. Think of a button that if pressed would roll a menu into the screen. Something like that.

Another cool example is the blackbox test: BlackBoxLua. You can push around a black box with your mouse on the screen.

Our example contains only 1 animation for that animationgroup. But each animationgroup can contain up to 100 animations and with
Code:
Animation:SetOrder(order)
You can preset an order in which they are going to be played.

More:
Widgets hierarchy | Animation | Alpha | Path | Rotation | Scale | Translation | AnimationGroup
Total Comments 0

Comments

 
Total Trackbacks 0

Trackbacks