Game Development Community

Health bar

by Fucifer · in Torque Game Builder · 08/01/2006 (6:27 pm) · 2 replies

What is the best way to add a health bar to the fish or shoot tutorial?

#1
08/01/2006 (7:57 pm)
Several thoughts occur to me ,but I'll stick with the easiest.

I think the easiest way is to have a 1x1 sprite thats white.

You use it as a StaticSprite, with blending to give it the color and alpha transp you want..

stretch its size to how large you want you health meter to be .

Then just resize it based on the health

function MyFish::Hit(%this,%damage)
{
      if (isObject(%this) && isObject(healthBar))
      {
       %this.hitpoints = %this.hitpoints - %damage;
       if (%this.hitpoints > 0 )
       {
              healthBar.setSize(%this.hitpoints SPC "10"); 
       } else {
              //Thanks for playing....
              gameOver(); 
       };
      }
}

then....in your collision code, whatever..

myFish.Hit(10);
#2
08/11/2006 (6:48 pm)
I think you have to also move it to the left or right by half of the setSize value to compensate for the size increase since the pivot point of the pixel is in the center.