Quantcast reliably setting color of frames - WoWInterface
Thread Tools Display Modes
02-07-20, 05:05 AM   #1
A Kobold Labourer
Join Date: Feb 2020
Posts: 1
Question reliably setting color of frames


I am working on a study project. I am creating multiple colored frames and I am trying to make them change their color.
I have tried to methods, the first one setting the color via SetTexture and then using SetColorTexture to change the color of the texture on the frame. This is very unreliable, (maybe I am initalising the farmes incorrectly...?) but they sometimes dont show up, or show up in black without the color changing. Doing a couple of /reload fixes them but, its a very undeterministic behaviour. They show up as white, but doesn't change. Code for this one, they somehow get stuck with being white:
local frame = CreateFrame("Frame", k, UIParent)
    frame:SetPoint("TOPLEFT", x, heightFromCorner)

      frame.texture = frame:CreateTexture()
    function(self, event)
The other method that I have tried was using SetBackdrop but that way the frames show up as green. I am trying to load a simple background texture, so it should be loadable, doing it like this:
      bgFile = [[Interface\AddOns\myaddon\data\backdrop.tga]],
      insets = {top = 0, left = 0, bottom = 0, right = 0},
I suspect something is off with the way I am trying to update the color of the frames, but since I assign a callback to the OnUpdate event, the update should be handled correctly.

Can you give any insights to this?

Thank you
  Reply With Quote
02-07-20, 07:40 AM   #2
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
  9. local function SetPlayerHealth(self, r, g, b)
  10.     self.texture:SetVertexColor(r, g, b)
  11. end
  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)
  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
  29. end)
  30. frame:RegisterEvent("UNIT_HEALTH_FREQUENT")
  31. SetPlayerHealth(frame, GetPlayerHealth("player")) -- set initial colours
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

WoWInterface » Developer Discussions » General Authoring Discussion » reliably setting color of frames

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off