Game Development Community

dev|Pro Game Development Curriculum

GuiImgHealthBarHud

by Ryan Mick · 02/23/2006 (9:42 am) · 43 comments

Download Code File

This control uses images to render health/energy, allowing us to have non-rectangular bars. I created this when I saw several posts about not being able to render health bars as curves, so I figured why not just render it as an image. If you have any problems post here and I will help you as best I can.

Instructions:

1. Add the files GuiImgHealthBarHud.cc and guiImgGenericBarHud.cc to the "engine\game\fps" directory and add to project.
2. Compile the project.
3. Replace playGui.gui with the one provided.
4. Add the images to "starter.fps\client\ui".
5. run Torque, and enjoy.

The long axis of the image must be a multiple of 100 pixels. This is because the control is based off of percentages. The flipped attribute determines which side the image is culled. For example:

An image that is 50 X 100 pixels would be culled from the top. By turning on flipped it would cull from the bottom.

The second control GuiImgGenericBarHud is a modified version of the GuiGenericBarHud control submitted by Robert Geiman I just added the image ability to it's functionality. All of the original functionality of his control should be intact, let me know if there are any problems with it.

Enjoy!!

update 2/22/06
Both controls now support dml list for animations. Up to 30 images can be specified.

New properties are:
1. animationRate. This is time in miliseconds the animation will change frames.
2. animationEnabled. This enables/disables the dml animation feature.
3. linkAnimationRateToValue. When enabled, this will increase the animation rate based on the value of the control.

New script methods are:
1. setShowAnimation(bool). This enables/disables the animation feature.
2. setAnimationRate(int). This is time in miliseconds the animation will change frames.
3. setAnimationFrame(int). This allows scripters to set what animation frame is viewed.

update 2/24/06
Updated both controls to support a onframechanged event.

New properties are:
1. enableFrameEvents. This enables/disables the frame event callback ability.

New script methods are:
1. setFrameEventsEnabled. This enables/disables the frame event callback ability.

New event:
1. onFrameChanged(obj, iframe). When enabled this and the control is using dml animation this event will be fired when the frames change.

update 5/21/2006
New property:
1. enforcesizerestriction. This is defaulted to true. This will allow you to disable the mulitple of 100px restriction, but

the image must still be at least 100px in the direction of action. When this is turned off the control will do it's best to

try and slice the image into equal slices but there will be cases of the slices being the same size and it will look like the

bar is not moving.
Page «Previous 1 2 3 Last »
#1
02/20/2006 (8:59 pm)
Forgot to mention that this is based off of stock TGE 1.4.
#2
02/22/2006 (8:27 am)
Looks pretty cool.

There's another resource which does almost the exact same thing.
What's the advantage of this resource over this one?

Can the image be any shape you like?

Not trying to put your resource down, just curious.
#3
02/22/2006 (9:08 am)
@Tim: Honestly, I had never seen that resource before.

This resource consists of just one new file to the engine, and you can use any image you want as long as it's long axis is in multiples of 100. This is is do to using a 0 to 100 percentage scale. I also allow for image pulsing just like the regular health bar. Basically it has all the goodies of the standard health/energy bar but you use an image. The best thing I can say is try them both out and see wich one you like best.
#4
02/22/2006 (9:21 am)
I think you may have sold me on yours with this line...
Quote:
I also allow for image pulsing just like the regular health bar.

Edit:

Just threw this in & it works great!
Love the fact it retains the original health settings like pulsing etc.
Easier to use than resource mentioned above

Only minor problem I had was you couldn't place a new instance of it in the gui editor in game or it crashed. Easy enough to set up in script though so not too bothered about that.
#5
02/22/2006 (10:51 am)
@Tim, I just discovered that problem and I have updated the file with the fix. Let me know if you have any other problems.

My next task is to make one that isn't bound to a player so that it can be used for other things. There is a resource already for one that is like the current health bar, so I'm just going to modify his with the image support. Once I have that one completed I'll post it here as well.
#6
02/22/2006 (12:52 pm)
I just updated the resource to include the GuiImgGenericBarHud control.
#7
02/22/2006 (8:41 pm)
Ok, last update. I just added the ability to both controls to use dml lists for animation. I have updated the readme file and the description above. Let me know if anyone has any problems.
#8
02/22/2006 (9:29 pm)
Thanks Ryan, very keen to give this another go. I don't think the zip has been updated however, I just downloaded it & it's the same as the original zip. Could you try uploading again so I can try out the dml's?

Alternatively, if you're not too busy email the file to me. I'm very keen to try the new features!
#9
02/23/2006 (7:20 am)
Ok, just uploaded the file again and confirmed that it has the updates. I'll send you the file as well just to be sure.
#10
02/23/2006 (12:26 pm)
Ryan, this resource looks great! I love the fact that you included a revised version of the GuiGenericBarHud resource with image support. I'm sure many people will find this resource VERY useful!
#11
02/23/2006 (12:45 pm)
Thanks Robert. The hard part is leaving it alone. Since I added the dml support I've been nagged by the idea of firing a script event when the frame changes but I think that's just starting to get to crazy. But it does allow for some realy cool possibilities, such as playing a sound when a certain frame hits. If people want it I'll put it in.
#12
02/23/2006 (9:05 pm)
Ryan, why stop now? Everything you've done thus far has been GREAT!

p.s. thanks for the email
#13
02/24/2006 (8:35 am)
Ok, I'll put it in and try to make it as flexible as I can. I'll also try to put together a video this weekend showing off the controls in action. Just don't expect any stellar graphics, I'm a coder and my art skills suck.
#14
02/24/2006 (12:01 pm)
Alright, I just posted an update with the frame change event callback functionality. Let me know if anyone has any problems or questions.
#15
02/25/2006 (1:41 pm)
Ryan, I just made an update to GuiGenericBarHud to use the alpha value when pulsing (originally it would pulse from nothing to full color, even if the alpha was set to say, 0.5).

I'm not sure if your resource uses the alpha value, but if so you can look at my last post in my resource to see exactly what changed.
#16
02/25/2006 (8:00 pm)
Extremely Useful - good work!
#17
02/26/2006 (10:11 am)
Here is a video showing some of the features of these controls. The heartbeat is triggered on the 12th frame of the health bar. The ammo hud is the guiImgGenericBarHud hooked in to the inventory. My artistic skills are lacking so please be kind.

Robert, I didn't realize your control set a starting alpha value. Not really needed in mine since you can set the inital transparency in the image but I might have to think about your solution.

Gavin, thanks!

Movie
#18
05/18/2006 (8:37 pm)
I'm having some trouble. When I have an GuiImgGenericBarHud which is blue and has a height of 250pix If I bring it to the right side of the screen it turns black and is invisible out of the GUI editor. It would also be nice if there wasn't a size limit, any way around that?
#19
05/19/2006 (7:24 am)
Sounds like the problem is the hieght of 250px. The size limit is to prevent the control from looking like no damage had occured. Let me explain a little bit better. When this control is created it takes the image and cuts it into 100 slices (1 slice for every percentage of health). When the image was not in a multiple of 100 there would be situations where slices would be the same size due to one slice being just a fraction different than another slice, and I could only use the integer part of the result. This made the control look as if nothing was happening at times when damage was applied. It wouldn't be hard to change the control back to allow different sizes but you will have the problem I described above. Let me know if I just confused the hell out of anyone.
#20
05/19/2006 (3:47 pm)
The effect I was shooting for was a proggress bar, but when I tried the other health bar resource it transfered over quite nicely. It doesn't have as many effects but I didn't want many. So for the proggress bar I can use that and for the health bar I can stick with this. Thanks.
Page «Previous 1 2 3 Last »