Thread Tools Display Modes
01-03-21, 12:20 AM   #1
Xaxziminrax the Second
A Murloc Raider
Join Date: Apr 2009
Posts: 5
Unconventionally shaped health bar issue

Hi, when experimenting with oUF I came across a healthbar style I like, which is fatter at low health so it's easier to notice. However, when implementing it, I realized that statusbars don't actually shrink or clip... they just slide along their axis.

Please look at this image on full life:


And now, when I am damaged:


The dark health bar is just moving, which makes sense for some layouts, but not for something like this. I had thought, due to some previous discussion, that unconventionally shaped status bars weren't a problem these days.

I'm unsure how to proceed to get the desired effect of just clipping off the end of the bar with the more damage you take.

Here's the current code generating my health bar. Any advice on what to add or change to be able to use this awkwardly-shaped health effectively would be very appreciated.

Lua Code:
  1. local Health = CreateFrame("StatusBar", "hiuiPlayerHealthBar", self)
  2.  
  3. --[[        Player Health Border (Art)
  4.             Art frame keeping the health bar in check.
  5. --]]
  6. local HealthBorder = Health:CreateTexture("hiuiPlayerHealthArt", "ARTWORK", nil, 1)
  7. HealthBorder:SetTexture(defaults.player.textures.border)
  8. HealthBorder:SetTexCoord(0, 377/512, 0, 60/64)
  9. HealthBorder:SetPoint("TOPLEFT", self, "TOPLEFT")
  10. HealthBorder:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT")
  11.  
  12.  
  13.  
  14. --[[        Player Health Status Bar
  15.             Dark bar that moves when you take damage.
  16. --]]
  17. Health:SetStatusBarTexture(defaults.player.textures.healthBarStretch)
  18. -- The border art on +1 and the bg on -1, so don't need this.
  19. --Health:GetStatusBarTexture():SetDrawLayer("ARTWORK", 0)
  20.  
  21. Health:SetPoint("TOPLEFT", HealthBorder, "TOPLEFT", 0, 0)
  22. Health:SetPoint("BOTTOMRIGHT", HealthBorder, "BOTTOMRIGHT", 0, 0)
  23.  
  24. Health:SetReverseFill(defaults.player.reverseFill);
  25. Health.frequentUpdates = defaults.player.frequent
  26.  
  27.  
  28.  
  29. --[[        Player Health Bar Background
  30.             Bright background that's revealed as damage is taken.
  31. --]]
  32. local HealthBg = Health:CreateTexture("hiuiPlayerHealthBg", "ARTWORK", nil, -1)
  33. HealthBg:SetTexture(defaults.player.textures.healthBgStretch)
  34.  
  35. HealthBg:SetPoint("TOPLEFT", HealthBorder, "TOPLEFT", 0, 0)
  36. HealthBg:SetPoint("BOTTOMRIGHT", HealthBorder, "BOTTOMRIGHT", 0, 0)
  37.  
  38.  
  39. self.Health = Health
  40.  
  41.  
  42. do -- bad practice, code abuse, programming under the influence
  43.     local function fixInnerElementsPos()
  44.         local l = 29/377 * hiuiPlayerHealthArt:GetWidth()
  45.         local t = 14/60 * hiuiPlayerHealthArt:GetHeight()
  46.  
  47.         hiuiPlayerHealthBar:SetPoint("TOPLEFT", "hiuiPlayerHealthArt", "TOPLEFT", l, -t)
  48.         hiuiPlayerHealthBar:SetPoint("BOTTOMRIGHT", "hiuiPlayerHealthArt", "BOTTOMRIGHT", -l, t)
  49.  
  50.         hiuiPlayerHealthBg:SetPoint("TOPLEFT", "hiuiPlayerHealthArt", "TOPLEFT", l, -t)
  51.         hiuiPlayerHealthBg:SetPoint("BOTTOMRIGHT", "hiuiPlayerHealthArt", "BOTTOMRIGHT", -l, t)
  52.     end
  53.  
  54.     C_Timer.After(0.8, fixInnerElementsPos)
  55. end
  Reply With Quote
10-23-22, 11:50 AM   #2
Coldkil
A Cliff Giant
 
Coldkil's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 70
The only real way to do it is by usong a scrollframe. You put two identical textures representing your full bar and the background (the red one). The scrollframe will "cut" the texture above displaying the one behind and give the illusion of a strangely shaped bar.
  Reply With Quote
10-23-22, 08:20 PM   #3
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
What you actually want to do is to create a mask texture that follows the outline of the health bar shape you want and then apply it to the status bar texture of your health bar.

Lua Code:
  1. local mask = Health:CreateMaskTexture()
  2. mask:SetTexture("path\\to\\your\\mask", "CLAMPTOBLACKADDITIVE", "CLAMPTOBLACKADDITIVE")
  3. mask:SetPoint("TOPLEFT", Health, "TOPLEFT", 0, 0)
  4. mask:SetPoint("BOTTOMRIGHT", Health, "BOTTOMRIGHT", 0, 0)
  5.  
  6. health:GetStatusBarTexture():AddMaskTexture(mask)

For instance, that's my old odd shaped unitframe (rip "round" layout ):


And here's the mask I used for its health bar:
__________________

Last edited by p3lim : 10-24-22 at 07:12 PM.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Unconventionally shaped health bar issue

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