Game Development Community

HOWTO - create a KOF like life bar[answered

by Chok Wei Tat · in Torque Game Builder · 10/15/2006 (5:33 am) · 2 replies

Hi, may some one give a helping hand on how to create a KOF(king of figther)/warcraft like life bar?

A rectangular, with another rectangular inside and is filled, which can reduce the width when the life reduced

Thanks

#1
10/15/2006 (11:16 am)
You'll need two images, one for what it looks like when your lifebar is full and one for when it's empty. If it's a Gui, create a GuiBitmapCtrl named LifeBarEmpty and set its bitmap property to the empty bitmap file at the full extent of the life bar. Then create a child GuiBitmapCtrl called LifeBarCurrent and initialize its extent to the same thing. When the player's life goes up or down, set the extent of LifeBarCurrent based on the ratio:
(currentLife / totalLife == extentTicks / totalTicks)
extentTicks = currentLife * totalTicks / totalLife

So you could use:
LifeBarCurrent.extent = (currentLife * getWord (LifeBarEmpty.extent, 0) / totalLife) SPC getWord (LifeBarCurrent.extent, 1)

For example if you have between 0 and 100 life and your life bar is 250 pixels wide, each hit point is worth 2.5 pixels. If they take 2hp damage, the new extent of LifeBarCurrent is 98 * 250 / 100 == 245.

Works the same with sprites using t2dStaticSprites and the size property instead of extent.
#2
10/15/2006 (5:30 pm)
Thanks Richard :) it worked!