WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Graphics Help (https://www.wowinterface.com/forums/forumdisplay.php?f=14)
-   -   texture drawing order? (https://www.wowinterface.com/forums/showthread.php?t=53149)

jeAz_ 02-26-16 02:19 AM

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?

SDPhantom 02-26-16 02:43 AM

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.

Yukyuk 02-26-16 04:44 AM

You could also set the sublevel while creating the texture.
wowprogramming.com/docs/widgets/Frame/CreateTexture

jeAz_ 02-26-16 05:43 AM

Quote:

Originally Posted by SDPhantom (Post 313223)
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 :)

jeAz_ 02-26-16 05:44 AM

Quote:

Originally Posted by Yukyuk (Post 313225)
You could also set the sublevel while creating the texture.
wowprogramming.com/docs/widgets/Frame/CreateTexture

Yeay!

Another good mehtod :D

Thank you!

SDPhantom 02-26-16 04:34 PM

Quote:

Originally Posted by Yukyuk (Post 313225)
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. :(


All times are GMT -6. The time now is 01:09 PM.

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