Originally Posted by myrroddin
If you had, say, 4 textures, and you only needed to show one at a time, something like this should work (taking from Phanx's lead).
** Edit: that is some wonky indentation, forum gods!
Code:
-- when you want to show a specific texture:
-- your textures are named "blabla1.tga", "blabla2.tga", etc
local counter
frame:SetScript("OnUpdate", function(self, elapsed)
for i = 1, 4 do
counter = counter + elapsed -- WoW increments in 0.1 seconds
frame.texture:SetTexture("Interface\\AddOns\\MyAddon\\textures\\blabla"..i)
frame:Show()
if counter == 2 then
-- hide this frame at two seconds
frame:Hide()
end
counter = 0
end
end)
|
You do realize that onupdate time is variable (as in: relative to FPS) right? :P Counter can also be a floating point variable, so using
greater than is better to prevent endless loops.
Here's some code to show an animation with a predefined duration:
lua Code:
local name, ns = ...
-- texture path. textures are in the addon folder as texture1.tga, texture2.tga, etcetera.
local path = "Interface\\AddOns\\"..name.."\\texture"
-- maxtime is the number of seconds the animation is allowed to run.
local maxtime = 2
-- running is the number of seconds since the animation was started.
local running = 0
-- the number of textures the animation consists of.
local numtextures = 4
-- the number of times the animation must run in *maxtime* seconds.
local times = 4
-- interval is the number of seconds between each texture change. If the entire animation is to run 4 times in 2 seconds, and the animation consists of 4 individual textures, then 2 / 4 / 4 = 0.125 seconds per texture:
local interval = maxtime / times / numframes
-- currenttexture is the currently active texture.
local currenttexture = 1
-- step holds the elapsed time between each texture change.
local step = 0
local frame = CreateFrame("Frame")
frame:Hide()
frame:SetSize(256,256)
frame.texture = frame:CreateTexture()
frame.texture:SetAllPoints()
frame:SetScript("OnUpdate", function(self, elapsed)
running = running + elapsed
step = step + elapsed
if running > maxtime then
return self:Hide()
end
if step < interval then
return
end
step = 0
currenttexture = currenttexture + 1
if currenttexture > numtextures then
currenttexture = 1
end
self.texture:SetTexture(path..currenttexture)
end)
frame:SetScript("OnShow", function(self)
running = 0
step = 0
currenttexture = 1
self.texture:SetTexture(path..1)
end)
This code is not tested but should probably work
Offcourse, this is even easier if you just use 1 texture, then you can just use the animation system.
EDIT: Is OP asking for an animation like this or is he asking for something like bloodsplatters on screen? I remember Resike coding something shiny for that to replace BloodyScreen.