Reply
Thread Tools Display Modes
Unread 11-24-13, 05:14 PM   #1
darksole
A Murloc Raider
Join Date: Aug 2013
Posts: 9
help with images

i am working on a addon for my guild, and have 4 images all are 256x256 tga files, i want to make them all pop on the screen in different spots when a mob dies for a set amount of time, i was looking at the Surprise addon witch does sort of the same thing with a image of the word congratulations, but i am lost as to how to accomplish this with the 4 images i have, do i need 4 different frames? or can they be the same frame? was using KillingBlow enhanced as a reference as well but it only pops up 1 image and it changes depending on faction were mine would be the same for every one. any help would be great thanks.
darksole is offline   Reply With Quote
Unread 11-24-13, 05:46 PM   #2
Malsomnus
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Apr 2013
Posts: 166
I'm almost certain that there should be no problem creating several textures on one frame.
I suppose you'd want a big invisible frame on the whole screen, with 4 textures somewhere on top of it.
Simply create a texture like this:
Code:
myFrame.tex1 = myFrame:CreateTexture ("Texture")
myFrame.tex1:SetTexture ("Interface\\Addons\\Surprise\\surprise1")
And then you can position the texture with SetPoint.

(Yay, someone likes my Surprise add-on!)
__________________
SanityCheck - Never again find yourself tanking Garrosh Hellscream in a wedding dress and a fishing rod!

Remember, every time you post a comment on an add-on, a kitten gets its wings!
Malsomnus is offline   Reply With Quote
Unread 11-24-13, 11:20 PM   #3
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,260
If you're only ever going to be showing one of the textures at a time, then you only need one texture object, and you can just change which texture it's displaying:

Code:
-- create the parent frame once:
local frame = CreateFrame("Frame", "MyAddon", UIParent)
frame:SetPoint("BOTTOM", UIParent, "CENTER", 0, 100)
frame:SetSize(256, 256)
frame:Hide()

-- create the texture object once:
local tex = frame:CreateTexture(nil, "ARTWORK")
tex:SetAllPoints(true)
frame.texture = tex

-- when you want to show a specific texture:
frame.texture:SetTexture("Interface\\AddOns\\MyAddon\\textures\\blabla")
frame:Show()
For the sake of not cluttering up framestacks, you should set the size and position of your frame, and have your texture inherit from that, rather than setting the frame to cover the whole screen and only positioning the texture.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Unread 11-25-13, 10:07 AM   #4
myrroddin
Premium Member
 
myrroddin's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 369
Originally Posted by Phanx View Post

Code:
-- create the parent frame once:
local frame = CreateFrame("Frame", "MyAddon", UIParent)
frame:SetPoint("BOTTOM", UIParent, "CENTER", 0, 100)
frame:SetSize(256, 256)
frame:Hide()

-- create the texture object once:
local tex = frame:CreateTexture(nil, "ARTWORK")
tex:SetAllPoints(true)
frame.texture = tex

-- when you want to show a specific texture:
frame.texture:SetTexture("Interface\\AddOns\\MyAddon\\textures\\blabla")
frame:Show()
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)
myrroddin is offline   Reply With Quote
Unread 11-25-13, 12:08 PM   #5
ravagernl
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,145
Originally Posted by myrroddin View Post
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:
  1. local name, ns = ...
  2.  
  3. -- texture path. textures are in the addon folder as texture1.tga, texture2.tga, etcetera.
  4. local path = "Interface\\AddOns\\"..name.."\\texture"
  5. -- maxtime is the number of seconds the animation is allowed to run.
  6. local maxtime = 2
  7. -- running is the number of seconds since the animation was started.
  8. local running = 0
  9. -- the number of textures the animation consists of.
  10. local numtextures = 4
  11. -- the number of times the animation must run in *maxtime* seconds.
  12. local times = 4
  13. -- 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:
  14. local interval = maxtime / times / numframes
  15. -- currenttexture is the currently active texture.
  16. local currenttexture = 1
  17. -- step holds the elapsed time between each texture change.
  18. local step = 0
  19. local frame = CreateFrame("Frame")
  20. frame:Hide()
  21. frame:SetSize(256,256)
  22. frame.texture = frame:CreateTexture()
  23. frame.texture:SetAllPoints()
  24. frame:SetScript("OnUpdate", function(self, elapsed)
  25.     running = running + elapsed
  26.     step = step + elapsed
  27.     if running > maxtime then
  28.         return self:Hide()
  29.     end
  30.     if step < interval then
  31.         return
  32.     end
  33.     step = 0
  34.     currenttexture = currenttexture + 1
  35.     if currenttexture > numtextures then
  36.         currenttexture = 1
  37.     end
  38.     self.texture:SetTexture(path..currenttexture)
  39. end)
  40. frame:SetScript("OnShow", function(self)
  41.     running = 0
  42.     step = 0
  43.     currenttexture = 1
  44.     self.texture:SetTexture(path..1)
  45. 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.

Last edited by ravagernl : 11-25-13 at 12:37 PM.
ravagernl is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » General Authoring Discussion » help with images

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