Thread Tools Display Modes
05-13-11, 03:04 PM   #1
felipers
A Defias Bandit
Join Date: Mar 2010
Posts: 3
AddOn doesn't load a texture properly

Hi guys,

I'm programming a very simple addon, just to learn a bit. It's a addon that shows a simple XP bar. The problem is that sometimes (not everytime), after reloading the UI, my status bar (that's inside a frame) doesn't appear. The rest of the UI loads normally, just my status bar doesn't appear. The code is below:

Code:
local function hex2rgb(hex)
	local r, g, b = string.sub(hex, 1, 2), string.sub(hex, 3, 4), string.sub(hex, 5, 6)
	return (tonumber(r, 16)/255), (tonumber(g, 16)/255), (tonumber(b, 16)/255)
end

local config = {
	borderColor = '222222',
	backgroundColor = '777777',
	borderSize = 1,
	align = 'CENTER',
	position = { x = 0, y = 0 },
	width = 300,
	height = 6
}

-- Background Frame
local bgframe = CreateFrame('Frame', nil)
bgframe:SetWidth(config.width)
bgframe:SetHeight(config.height)
bgframe:SetPoint(config.align, config.position.x, config.position.y)
bgframe:SetFrameStrata('LOW')
bgframe.texture = bgframe:CreateTexture()
bgframe.texture:SetAllPoints(bgframe)
bgframe.texture:SetTexture(hex2rgb(config.borderColor))

-- Status Bar Frame -> this is the guy that doesn't appear
local StatusBar = CreateFrame('StatusBar', nil, bgframe)
StatusBar:SetWidth(config.width - (2 * config.borderSize))
StatusBar:SetHeight(config.height - (2 * config.borderSize))
StatusBar:SetPoint('TOPLEFT', config.borderSize, config.borderSize * (-1))
StatusBar.texture = StatusBar:CreateTexture()
StatusBar.texture:SetAllPoints(StatusBar)
StatusBar.texture:SetTexture(hex2rgb(config.backgroundColor))
StatusBar:SetMinMaxValues(0, 100)
StatusBar:SetValue(50) -- 50% just for tests

local _, playerClass = UnitClass("player")
local classColor = RAID_CLASS_COLORS[playerClass]
local r, g, b = classColor.r, classColor.g, classColor.b
local BarTexture = StatusBar:CreateTexture()
BarTexture:SetGradient('VERTICAL', 0.3, 0.3, 0.3, 0.8, 0.8, 0.8)
BarTexture:SetTexture(r, g, b)
StatusBar:SetStatusBarTexture(BarTexture) -- maybe the problem is here, really dunno
Really don't know what is the problem

Sry for my poor english.

-- Editing

In order to explain better, there's a image below:


Last edited by felipers : 05-14-11 at 08:27 AM.
  Reply With Quote
05-13-11, 06:32 PM   #2
Crissa
A Flamescale Wyrmkin
 
Crissa's Avatar
Join Date: May 2008
Posts: 136
Your english is fine. I just have no idea.

-Crissa
  Reply With Quote
05-14-11, 09:10 AM   #3
felipers
A Defias Bandit
Join Date: Mar 2010
Posts: 3
Hi guys,

After a bunch os tries, I think I got it.

I changed the following line:

Code:
StatusBar:SetStatusBarTexture(BarTexture)
by:

Code:
StatusBar:SetStatusBarTexture(BarTexture, "OVERLAY")
I tried the following parameters:
  • BACKGROUND - The bar doesn't appear (but the bar's gray background works normally)
  • BORDER - Same as above
  • ARTWORK - same as above, but SOMETIMES (that's the strange thing) it worked (just like empty parameter)
  • OVERLAY - worked always lol

I fixed it, but I still would like to know WHY the artwork/empty parameter just works sometimes.
  Reply With Quote
05-14-11, 09:32 AM   #4
Waky
A Cobalt Mageweaver
 
Waky's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 200
I'm pretty sure when you create a texture without specifying its layer it will default to ARTWORK. That being said, if your gray bar is artwork and your green bar is artwork and they're on the same level it's possible that the gray was just on top of the green bar.

That's all I can think of, glad to see you got it working though!
  Reply With Quote
05-14-11, 10:14 AM   #5
felipers
A Defias Bandit
Join Date: Mar 2010
Posts: 3
Waky, that's exactly what I think (green bar behind gray bar). The strange is why sometimes it works and sometimes it doesn't. Maybe that's something in the low level (rendering) processing.

Thank you for your comment.

Last edited by felipers : 05-14-11 at 01:36 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » AddOn doesn't load a texture properly

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