Thread: Status bar
View Single Post
04-24-21, 03:30 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
The animation system rotates the entire UI object, not really something you want for a statusbar. What I've seen done is create a rotating texcoord set that adjusts its size to match whatever height adjustments you make to the bar.

Lua Code:
  1. local HalfSQRT2,LLAngle,LRAngle,UAngle=(2^0.5)/2,0.75*math.pi,0.25*math.pi,1.5*math.pi;
  2. local function Vector(x,y,angle,dist) return x+math.cos(angle)*dist,y+math.sin(angle)*dist; end
  3. local function CalcTexCoord(angle,percent)
  4.     local LLx,LLy=Vector(0.5,0.5,LLAngle+angle,HalfSQRT2);
  5.     local LRx,LRy=Vector(0.5,0.5,LRAngle+angle,HalfSQRT2);
  6.     local ULx,ULy=Vector(LLx,LLy,UAngle+angle,percent);
  7.     local URx,URy=Vector(LRx,LRy,UAngle+angle,percent);
  8.     return ULx,ULy,LLx,LLy,URx,URy,LRx,LRy;
  9. end
  10.  
  11. local ManaFrame=CreateFrame("Frame",nil,UIParent);--    Container for mana orb texture
  12. ManaFrame:SetPoint("CENTER");
  13. ManaFrame:SetSize(256,256);
  14.  
  15. local ManaOrb=ManaFrame:CreateTexture(nil,"ARTWORK");
  16. ManaOrb:SetTexture("Interface\\AddOns\\YourAddOn\\PathToFile");--   Set to whatever your texture is
  17. ManaOrb:SetPoint("BOTTOM");--   Attach to bottom of frame
  18. ManaOrb:SetSize(ManaFrame:GetSize());-- Init to frame size
  19.  
  20. ManaFrame.PercentValue=1;-- Init
  21. ManaFrame:SetScript("OnUpdate",function(self) HealthOrb:SetTexCoord(CalcTexCoord((GetTime()%2)*math.pi,self.PercentValue)); end);
  22.  
  23. ManaFrame.Unit="player";
  24. ManaFrame:RegisterUnitEvent("UNIT_DISPLAYPOWER",ManaFrame.Unit);
  25. ManaFrame:RegisterUnitEvent("UNIT_POWER_UPDATE",ManaFrame.Unit);
  26. ManaFrame:RegisterUnitEvent("UNIT_MAXPOWER",ManaFrame.Unit);
  27. ManaFrame:SetScript("OnEvent",function(self,event,...)
  28.     if select(2,UnitPowerType(self.Unit))=="MANA" then
  29.         local percent=UnitPower(self.Unit)/UnitPowerMax(self.Unit);
  30.         ManaOrb:SetHeight(self:GetHeight()*percent);--  Adjust texture height
  31.         ManaOrb.PercentValue=percent;-- Texcoord updates from OnUpdate script
  32.         self:Show();
  33.     else self:Hide(); end
  34. end);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote