Thread Tools Display Modes
02-26-16, 02:19 AM   #1
jeAz_
A Deviate Faerie Dragon
Join Date: Feb 2016
Posts: 13
texture drawing order?

Hi all,

So, I was trying to create a cast bar and reached here to ask a question regarding drawing orders of texture.

Please have a look at the lines of code that I wrote:
Lua Code:
  1. A.CreateCastBar = function(f, unit)
  2.     local point, relativeTo, relativePoint, xOfs, yOfs = unpack(G[unit]["castbar"]["point"]);
  3.  
  4.     local CastBar = CreateFrame("Frame", f:GetName() .. "CastBar", f);
  5.     CastBar:SetSize(G[unit]["castbar"]["width"], G[unit]["castbar"]["height"]);
  6.     CastBar:SetPoint(point, relativeTo, relativePoint, xOfs, yOfs);
  7.  
  8.     local Bar = CreateFrame("StatusBar", nil, CastBar);
  9.     Bar:SetSize(CastBar:GetWidth() - 36, CastBar:GetHeight() - 4);
  10.     Bar:SetPoint("RIGHT", CastBar, "RIGHT", -2, 0);
  11.     Bar:SetStatusBarTexture(BACKDROP);
  12.     Bar:SetStatusBarColor(0.5, 0.5, 1, 1);
  13.  
  14.     CastBar.Bar = Bar;
  15.  
  16.     local bg = Bar:CreateTexture(nil, "BACKGROUND");
  17.     bg:SetAllPoints(true);
  18.     bg:SetTexture(BACKDROP);
  19.     bg:SetVertexColor(1, 1, 1, 1);
  20.  
  21.     CastBar.bg = bg;
  22.  
  23.     local background = Bar:CreateTexture(nil, "BACKGROUND");
  24.     background:SetSize(Bar:GetWidth() + 4, Bar:GetHeight() + 4);
  25.     background:SetPoint("CENTER", Bar, "CENTER", 0, 0);
  26.     background:SetTexture(BACKDROP);
  27.     background:SetVertexColor(0.1, 0.1, 0.1, 1);
  28.  
  29.     CastBar.background = background;
  30.  
  31.     local Icon = CreateFrame("Frame", nil, CastBar);
  32.     Icon:SetSize(CastBar:GetHeight() - 4, CastBar:GetHeight() - 4);
  33.     Icon:SetPoint("LEFT", CastBar, "LEFT", 2, 0);
  34.  
  35.     CastBar.Icon = Icon;
  36.  
  37.     local texture = Icon:CreateTexture(nil, "OVERLAY");
  38.     texture:SetAllPoints(true);
  39.     texture:SetTexture(BACKDROP);
  40.     texture:SetVertexColor(0.5, 0.5, 1, 1);
  41.  
  42.     Icon.texture = texture;
  43.  
  44.     background = Icon:CreateTexture(nil, "BACKGROUND");
  45.     background:SetSize(Icon:GetWidth() + 4, Icon:GetHeight() + 4);
  46.     background:SetPoint("CENTER", Icon, "CENTER", 0, 0);
  47.     background:SetTexture(BACKDROP);
  48.     background:SetVertexColor(0.1, 0.1, 0.1, 1);
  49.  
  50.     Icon.background = background;
  51. end

and my problematic part is here:
Lua Code:
  1. local bg = Bar:CreateTexture(nil, "BACKGROUND");
  2. bg:SetAllPoints(true);
  3. bg:SetTexture(BACKDROP);
  4. bg:SetVertexColor(1, 1, 1, 1);
  5.  
  6. CastBar.bg = bg;
  7.  
  8. local background = Bar:CreateTexture(nil, "BACKGROUND");
  9. background:SetSize(Bar:GetWidth() + 4, Bar:GetHeight() + 4);
  10. background:SetPoint("CENTER", Bar, "CENTER", 0, 0);
  11. background:SetTexture(BACKDROP);
  12. background:SetVertexColor(0.1, 0.1, 0.1, 1);
  13.  
  14. CastBar.background = background;

Since "bg" and "background" are drawn on same layer, it does not draw "bg" on screen.

Any helps please?
  Reply With Quote
02-26-16, 02:43 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
You can use the second argument of Texture:SetDrawLayer() to specify a sublevel that the texture is drawn on. This allows you to set which texture is on top from within the same draw layer.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
02-26-16, 04:44 AM   #3
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
You could also set the sublevel while creating the texture.
wowprogramming.com/docs/widgets/Frame/CreateTexture
__________________
Better to fail then never have tried at all.
  Reply With Quote
02-26-16, 05:43 AM   #4
jeAz_
A Deviate Faerie Dragon
Join Date: Feb 2016
Posts: 13
Originally Posted by SDPhantom View Post
You can use the second argument of Texture:SetDrawLayer() to specify a sublevel that the texture is drawn on. This allows you to set which texture is on top from within the same draw layer.
Hi SDPhantom,

I wasn't unsure of Texture:SetDrawLayer() so I did not give it a try on it.

It works perfectly!

Thank you
  Reply With Quote
02-26-16, 05:44 AM   #5
jeAz_
A Deviate Faerie Dragon
Join Date: Feb 2016
Posts: 13
Originally Posted by Yukyuk View Post
You could also set the sublevel while creating the texture.
wowprogramming.com/docs/widgets/Frame/CreateTexture
Yeay!

Another good mehtod

Thank you!
  Reply With Quote
02-26-16, 04:34 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Yukyuk View Post
You could also set the sublevel while creating the texture.
wowprogramming.com/docs/widgets/Frame/CreateTexture
Sadly, I still use WoWPedia as my main source and I keep finding more things that are out of date.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » Graphics Help » texture drawing order?

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