WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Graphics Help (https://www.wowinterface.com/forums/forumdisplay.php?f=14)
-   -   Pulsing background? (https://www.wowinterface.com/forums/showthread.php?t=58202)

thatrickguy 09-08-20 09:14 PM

Pulsing background?
 
Trying to make the background of my frame pulsing red, but it takes a couple of big steps from black to bright red, but then never comes back down to black. I can see the value of r climb from 0 to 1 and back down to 0, but the frame color never changes after it hits red. Thoughts?

Code:

local seconds = 0.5
local total = 0

local r = 0
local rud = 0.2

SPHowFrame:SetScript("OnUpdate", function(self, elapsed)
        total = total + elapsed
        if total > seconds then
      local r = getRedColor()
      print (r)
      self.texture = nil
      self.texture = self:CreateTexture(nil,"BACKGROUND")
      self.texture:SetColorTexture(r, 0, 0)
      self.texture:SetAllPoints(self)
      self.texture = t
      total = 0
        end
end)


function getRedColor()
  r = r + rud
  if r > 1 then
      rud = rud * -1
      r=1
  end
  if r < 0 then
      rud = rud * -1
      r=0
  end
 
  return r
end


Fizzlemizz 09-08-20 09:54 PM

For this example, you're creating a new texture every update. Create it once when you create the frame and adjust that texture.

Lua Code:
  1. local SPHowFrame = CreateFrame("Frame", nil, UIParent)
  2. SPHowFrame:SetSize(50, 50)
  3. SPHowFrame:SetPoint("CENTER")
  4. SPHowFrame.texture = SPHowFrame:CreateTexture()
  5. SPHowFrame.texture:SetAllPoints()
  6. SPHowFrame.texture:SetTexture("Interface/Buttons/WHITE8X8")
  7.  
  8. local seconds = 0.5
  9. local total = 0
  10.  
  11. local r = 0
  12. local rud = 0.2
  13.  
  14. SPHowFrame:SetScript("OnUpdate", function(self, elapsed)
  15.     total = total + elapsed
  16.     if total > seconds then
  17.       local r = getRedColor()
  18.       print (r)
  19.       self.texture:SetColorTexture(r, 0, 0)
  20.       total = 0
  21.     end
  22. end)
  23.  
  24.  
  25. function getRedColor()
  26.    r = r + rud
  27.    if r > 1 then
  28.       rud = rud * -1
  29.       r=1
  30.    end
  31.    if r < 0 then
  32.       rud = rud * -1
  33.       r=0
  34.    end
  35.    
  36.    return r
  37. end

thatrickguy 09-08-20 10:34 PM

Perfect, thanks!


All times are GMT -6. The time now is 04:34 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI