View Single Post
07-23-16, 10:56 PM   #3
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by SDPhantom View Post
1: If you're using the backdrop system, just set it on the StatusBar. You can also create textures directly on them so there's no need to create container frames for them and waste resources.

2: You have your health bar at FrameLevel 3 and power bar at FrameLevel 2. When you create a frame that's a child of another, it automatically gets its parent's FrameLevel+1. This means the container frames you use for textures and backdrops for the power bar share the same FrameLevel with your health bar and are melding together with it. This could be fixed easily by following the answer above.
Normally, you shouldn't mess with FrameLevel unless you need to bump it up by a specific amount. Don't set it to a solid number. For example, leave your power bar at its default and do this instead on your health bar: Health:SetFrameLevel(Health:GetFrameLevel()+1)
Hi SDPhantom,

Based on your advice, I made some modifications, but I'm unsure whether I did correctly or not.

Please have a look at the code below:
Lua Code:
  1. A.CreateHealth = function(f, unit)
  2.     A.CreateHealthBar(f, unit);
  3.     A.CreateHealthText(f, unit);
  4. end
  5.  
  6. A.CreateHealthBar = function(f, unit)
  7.     local Health = CreateFrame("StatusBar", f:GetName() .. "HealthBar", f);
  8.     Health:SetFrameLevel(Health:GetFrameLevel() + 1);
  9.     Health:SetStatusBarTexture(HEALTH_BAR);
  10.     Health:SetStatusBarColor(0, 0, 0, 1);
  11.  
  12.     if unit == "player" then
  13.         Health:SetPoint("TOPRIGHT", f, "TOPRIGHT", 0, 0);
  14.         Health:SetSize(f:GetWidth() - 10, f:GetHeight() - 10);
  15.     end
  16.  
  17.     Health:SetBackdrop({
  18.         edgeFile = BACKDROP,
  19.         edgeSize = 1,
  20.         insets = {
  21.             left = 1,
  22.             right = 1,
  23.             top = 1,
  24.             bottom = 1,
  25.         },
  26.     });
  27.     Health:SetBackdropBorderColor(1, 0, 0, 1);
  28.  
  29.     Health.bg = Health:CreateTexture(nil, "BACKGROUND");
  30.     Health.bg:SetAllPoints(true);
  31.     Health.bg:SetTexture(BACKDROP);
  32.     Health.bg:SetVertexColor(0.5, 0.5, 0.5, 1);
  33.  
  34.     f.Health = Health;
  35.     f.Health.bg = Health.bg;
  36. end
  37.  
  38. A.CreateHealthText = function(f, unit)
  39.  
  40. end
  41.  
  42. A.CreatePower = function(f, unit)
  43.     A.CreatePowerBar(f, unit);
  44.     A.CreatePowerText(f, unit);
  45. end
  46.  
  47. A.CreatePowerBar = function(f, unit)
  48.     local Power = CreateFrame("StatusBar", f:GetName() .. "PowerBar", f);
  49.     Power:SetFrameLevel(f.Health:GetFrameLevel() - 1);
  50.     Power:SetStatusBarTexture(HEALTH_BAR);
  51.     Power:SetStatusBarColor(1, 1, 1, 1);
  52.  
  53.     if unit == "player" then
  54.         Power:SetPoint("BOTTOMLEFT", f, "BOTTOMLEFT", 0, 0);
  55.         Power:SetSize(f:GetWidth() - 10, f:GetHeight() - 10);
  56.     end
  57.  
  58.     Power:SetBackdrop({
  59.         edgeFile = BACKDROP,
  60.         edgeSize = 1,
  61.         insets = {
  62.             left = 1,
  63.             right = 1,
  64.             top = 1,
  65.             bottom = 1,
  66.         },
  67.     });
  68.     Power:SetBackdropBorderColor(0, 0, 1, 1);
  69.  
  70.     f.Power = Power;
  71. end
  72.  
  73. A.CreatePowerText = function(f, unit)
  74.  
  75. end

This currently results in...



The frame level issue has been successfully fixed(?), but the border issue is still remaining.

The backdrop has been added directly to the status bar frame, but it seems to be sitting right behind the status bar so that the border is only shown when the unit loses the health.
(Which is same for PowerBar as well)

I have gone through the API to review how SetBackdrop function works and could not figure it out

The image file that I used for edgeFile can be found on the attachment.
(Which is just 16x16 white square in fact...)
Attached Files
File Type: blp backdrop.BLP (1.3 KB, 93 views)
  Reply With Quote