Quantcast WoWInterface - View Single Post - reliably setting color of frames
View Single Post
02-07-20, 07:40 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,203
You don't tell us what the Set and Get functions are doing (setting the colours I'm guessing at here). Also, OnEvent and OnUpdate are two different scripts to do two different things. The game will trigger health update events which might be better in this situation than using OnUpdate which will cycle far more often than health gets updated (especially out of combat).

Something like:

Lua Code:
  1. local function GetPlayerHealth(unit)
  2.     local max = UnitHealthMax(unit)
  3.     local health = UnitHealth(unit)
  4.     --local r, g, b = ...
  5.     -- do the math, get the colours
  6.     return r, g, b
  7. end
  8.  
  9. local function SetPlayerHealth(self, r, g, b)
  10.     self.texture:SetVertexColor(r, g, b)
  11. end
  12.  
  13. local frame = CreateFrame("Frame", k, UIParent)
  14. frame:SetPoint("TOPLEFT", x, heightFromCorner)
  15. frame:SetHeight(BOX_SIZE)
  16. frame:SetWidth(BOX_SIZE)
  17. frame.texture = frame:CreateTexture()
  18. frame.texture:SetAllPoints(frame)
  19. frame.texture:SetTexture("Interface/BUTTONS/WHITE8X8")
  20. --frame.texture:SetColorTexture(1,1,1,1)
  21.  
  22. frame:SetScript("OnEvent", function(self, event, ...)
  23.     -- don't need to check for the event type because only one is registered.
  24.     local unit = ...
  25.     if unit == "player" then
  26.         SetPlayerHealth(self, GetPlayerHealth(unit))
  27.     end
  28.    
  29. end)
  30. frame:RegisterEvent("UNIT_HEALTH_FREQUENT")
  31. SetPlayerHealth(frame, GetPlayerHealth("player")) -- set initial colours
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 02-07-20 at 12:03 PM.
  Reply With Quote