Thread Tools Display Modes
03-19-18, 03:51 AM   #1
Ethly
A Fallenroot Satyr
Join Date: Mar 2018
Posts: 23
What's the most performant way to draw unit frame health bar?

I want to display unit frame with health, incoming heal, heal absorb, damage absorb, and health deficit. Basically it's 5 adjacent rectangles with different colors. Currently I'm considering 3 different implementations and I don't know which one would be the most performant.

1. Put 4 statusbars for every value and one texture below for health deficit. All statusbars will be fixed, frame levels will be adjusted for proper z-order.

2. Put 4 textures for every value and one texture below. Textures will have fixed left side and Lua will change their width. With something like textureSublevel they will have proper z-order.

3. Put 5 textures one after other using anchors. They will have the same level, but they won't overlap, so it's not a problem.

3-rd variant looks like the best one, because game won't have to redraw pixels multiple times and theoretically could render textures simultaneously, but it seems significantly harder to implement with Lua (because I have to hide unused textures and rearrange their anchors all the time). Also I'm not sure if this layout mechanism performant enough.
  Reply With Quote
03-19-18, 05:22 AM   #2
jukx
A Murloc Raider
 
jukx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 7
1. and 2. definitely don't seem to be the way to go. You'd have to recalculate the absorb bar width every time the health amount changes i.e. at each regen tick.

Your 3rd option comes close to how oUF suggests doing it which also looks sensible to me.

Lua Code:
  1. -- Position and size
  2.     local myBar = CreateFrame('StatusBar', nil, self.Health)
  3.     myBar:SetPoint('TOP')
  4.     myBar:SetPoint('BOTTOM')
  5.     myBar:SetPoint('LEFT', self.Health:GetStatusBarTexture(), 'RIGHT')
  6.     myBar:SetWidth(200)
  7.     local otherBar = CreateFrame('StatusBar', nil, self.Health)
  8.     otherBar:SetPoint('TOP')
  9.     otherBar:SetPoint('BOTTOM')
  10.     otherBar:SetPoint('LEFT', myBar:GetStatusBarTexture(), 'RIGHT')
  11.     otherBar:SetWidth(200)
  12.     local absorbBar = CreateFrame('StatusBar', nil, self.Health)
  13.     absorbBar:SetPoint('TOP')
  14.     absorbBar:SetPoint('BOTTOM')
  15.     absorbBar:SetPoint('LEFT', otherBar:GetStatusBarTexture(), 'RIGHT')
  16.     absorbBar:SetWidth(200)
  17.     local healAbsorbBar = CreateFrame('StatusBar', nil, self.Health)
  18.     healAbsorbBar:SetPoint('TOP')
  19.     healAbsorbBar:SetPoint('BOTTOM')
  20.     healAbsorbBar:SetPoint('RIGHT', self.Health:GetStatusBarTexture())
  21.     healAbsorbBar:SetWidth(200)
  22.     healAbsorbBar:SetReverseFill(true)

Although to save some calculations please do use a 100% width texture below the whole bar for the deficit.

(because I have to hide unused textures and rearrange their anchors all the time)
Well you'd only have to set their anchors once, WoW does the moving behind the scenes (in an optimized fashion, one would hope). Also, aren't textures with width 0 (or empty statusbars) invisible by default?
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » What's the most performant way to draw unit frame health bar?

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