Game Development Community

dev|Pro Game Development Curriculum

A health bitmap (like in Project IGI)

by Michael Schoonbrood · 01/27/2002 (2:08 pm) · 23 comments

Download Code File

The png files are very ugly, because I can't draw.
I think our artist would be seriously pissed if I gave you his, so I can't do that either!
If there's anyone out there who wants to draw the public some nice ones, then please do so!

The control is based upon the guiBitmapCtrl on the Torque site.
I didn't modify that class, I'm only using it (subclassed from it!).
So you need it and I included it in this zip.
If you already have it installed, then leave it be... you don't have to replace it!

The new class is called GuiHealthBitmapCtrl
Check the bottom of this file to see how it's included on screen.
You can add it thru the GUI editor, but I recommend copy and pasting it into the playGui.cs file.
I introduced a new Setting for it, called bitmapStyle.
It's currently supports "DAMAGE" and "HEALTH" (default). The setting should be case insensitive!
Damage shows the sustained damage (bitmap grows) and health shows your remaining health
(bitmap shrinks).

I don't think it will work correctly with stretching bitmaps.
So make sure your on-screen size is the same as the actual PNG size.
My png is 45x128. So the size of the onscreen control is the same (extent = "45 128";)

Feel free to expand upon this control, but do the community a favor,
and post your newer version on here as well! That way we'll all grow!


If anything is unclear, post on the forum. I check there regularly.
You can mail me at torque@madbutch.com. But always post on the forum!
Anything I answer on the forum can be used by everyone! That's why I prefer it.


==================
-- installation --
==================

Copy the following 4 source files:
- guiBitmapCtrl.cc (not mine and unmodified, it's from a sample at the torque site)
- guiBitmapCtrl.h (if you already have these 2 installed, then leave them!)
- guiHealthBitmapCtrl.cc (based upon the above guiBitmapCtrl, but a new class)
- guiHealthBitmapCtrl.h
to the engine\gui dir.


Now follow these steps to include the files in your EXE:
- Open the Torque project in MSVC.
- Select the Torque Demo Files sample
- Open the Source Files Folder
- Open the Gui folder
- Right click on the Gui folder and select Add files to folder
- Select Files of type: All files
- Select the above 4 files and add them.
- Build the new exe


Copy the 3 png files to the example dir, in: fps\client\ui


Add this to the bottom of your playGui.gui (fps\client\ui) and run!
Add it BEFORE the last };

new GuiHealthBitmapCtrl() {
      profile = "GuiDefaultProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "25 350";
      extent = "45 128";
      minExtent = "8 8";
      visible = "1";
      helpTag = "0";
      bitmap = "./LifeBarHealth.png";
      wrap = "1";
      showHealth = "1";
      bitmapStyle = "health";
   };
   new GuiBitmapCtrl() {
      profile = "GuiDefaultProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "25 350";
      extent = "45 128";
      minExtent = "8 8";
      visible = "1";
      helpTag = "0";
      bitmap = "./LifeBarFrame.png";
      wrap = "1";
   };
   new GuiHealthBitmapCtrl() {
      profile = "GuiDefaultProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "75 350";
      extent = "45 128";
      minExtent = "8 8";
      visible = "1";
      helpTag = "0";
      bitmap = "./LifeBarDamage.png";
      wrap = "1";
      showHealth = "1";
      bitmapStyle = "damage";
   };
   new GuiBitmapCtrl() {
      profile = "GuiDefaultProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "75 350";
      extent = "45 128";
      minExtent = "8 8";
      visible = "1";
      helpTag = "0";
      bitmap = "./LifeBarFrame.png";
      wrap = "1";
   };
Page «Previous 1 2
#1
01/28/2002 (6:54 am)
im working on making this one better michael... ill let you know what stuff i modify, btw contact me via icq
#2
01/28/2002 (10:16 am)
Ok.. keep me posted.

One idea i had myself, is add a member variable to the class which stores the previous height value.

If health depletes, let's say by 10, then it would be cool to make the bitmap smaller pixel by pixel. But then I need to know the time ellapsed since the last update and stuff.

Should be doable... But I'm still getting used to the engine :) So it might take a while
#3
01/28/2002 (4:57 pm)
ahh i see what you mean... sounds nice to me :)
what i was working on was trying to have 1 gui ctrl that displays both the bar and the frame, and also trying not to use the complicated guiBitmapCtrl code :)
#4
01/29/2002 (7:09 pm)
good job explaining the install i had no probs with this ,altho i must say i like how the torque default health works better
#5
05/01/2002 (11:20 am)
Correct me if im wrong, but There isnt a strupr() function in strings.h, and im compilling using GCC.

--mafoo
#6
05/01/2002 (11:20 am)
Correct me if im wrong, but There isnt a strupr() function in strings.h, and im compilling using GCC.

--mafoo
#7
11/14/2002 (3:36 am)
To get non wrap to work, I use the following code:

Replace (around line 117):
-------------------------------------------
// Unfinished! Only with wrap on works correctly now!
// ToDoMB: Add support for stretched images!
dglDrawBitmapStretch(mTextureHandle, targetRect);
-------------------------------------------

With the following...
-------------------------------------------
RectI srcRegion;
RectI dstRegion;

int xshift = startPoint.x % mBounds.extent.x;
int yshift = startPoint.y % mBounds.extent.y;

// Calculate the new Y OffSet
newYOffSet = offset.y + ( mBounds.extent.y - (newHeight * mBounds.extent.y) / texture->bitmapHeight);
srcRegion.set( 0, texture->bitmapHeight - newHeight, texture->bitmapWidth, newHeight );
dstRegion.set( offset.x - xshift, newYOffSet - yshift, mBounds.extent.x, (newHeight * mBounds.extent.y) / texture->bitmapHeight);

dglDrawBitmapStretchSR( texture, dstRegion, srcRegion, false );
--------------------------------------------

It might not be perfect, but it works in the case I need it to.
#8
01/14/2004 (11:58 pm)
can anyone update this resource to the current head for me please.
#9
02/13/2004 (11:54 pm)
This code works in head unmodified (and works in 1.2)
#10
02/14/2004 (1:16 am)
News to me, i put it in unmodified with a brand new head, and i get an error about bitmap array's
#11
02/23/2004 (7:08 pm)
There is a mac compatibilty problem with this resource.

dStrupr does *not* work in TGE 1.2 or 1.2.1 for the mac so it will always use the Health style rendering and never the damage one.

The resource also uses strings.h for strcmp() which is not necessary as TGE has its platform friendly dStrcmp().

A bug fix for dStrupr for the mac has been submitted.
#12
04/09/2004 (11:18 pm)
<>
#13
04/18/2004 (10:32 am)
i got
E:\Torque\Mystic Past\Current\torque\engine\gui\guiHealthBitmapCtrl.cc(19): error C2248: 'GuiBitmapCtrl::Parent' : cannot access private typedef declared in class 'GuiBitmapCtrl'
#14
08/23/2004 (8:26 am)
*bump*

there have been substantial changes to the code this feature inherits, can someone more cluey than i please look over this?
#15
08/23/2004 (8:55 am)
ok after a bit of looking around i fixed this for Torque 1.2.2

change in the header file

class GuiHealthBitmapCtrl : public GuiBitmapCtrl
{
typedef GuiBitmapCtrl Parent; //add this line

and in the content file

find the if statement containing

newHeight = (S32)( (F32)mBounds.extent.y * ( 1 - damage ) );

and remove the if leaving the option you want either health or damage (damage being the condition statement)
then compile and enjoy.


ps.s i havent posted a fix before and its 5 in the morning. so be nice.
#16
12/17/2004 (2:22 pm)
Thanks. Works great.
#17
11/17/2005 (6:38 pm)
For those using a post 1.3 codebase, implement Andrews changes as well as changing the following statement in GuiHealthBitmap.cc - GuiHealthBitmapCtrl::onRender() as illustrated:
//GameConnection *con	= GameConnection::getServerConnection();
	GameConnection *con = GameConnection::getConnectionToServer();

Compiles clean. =)
#18
02/22/2006 (8:19 am)
@ Andrew Osborne

I know this resource is getting old but your fix above has me scratching my head.

I dropped this into 1.4 without any problems whatsover, except some minor code changes of where the gui includes are and the infamous getConnectionToServer();

Why break the health, damage thing in head code to one or the other? Just set it in the gui to HEALTH or DAMAGE. They both work fine.
#19
05/19/2006 (6:50 pm)
How would I go about flipping the bar so it goes from bottom to top?
#20
05/22/2006 (8:10 am)
What is MSVC?
Page «Previous 1 2