Displaying Hud
by Keith Mc Dowell JR · in Torque Game Builder · 06/07/2007 (8:46 pm) · 5 replies
Hey, I can see to find the post regarding displaying a hud using the GuiBitmapCtrl using two pictures, once of the bitmap shows full stats and then the other is not full. But, I can seem to find that post..
Any one, attempting to do this using GuiBitmapctrl
Any one, attempting to do this using GuiBitmapctrl
#2
I came across a post that was describing how to display a (say a health bar) that is full and depending on what is happening it would update the color bar. (Silly me) I forgot book mark the page. The post describe that you would make two GuiBitmapctrl. One with health bar full and the other one empty, and it also went on how to update the bar, but at last I can seem to find that posted.. I also believe it was mixed in with a simple modification to GuiEditor.ed.cs; so when you switch to GUI Builder and save it toggle backs to the levelbuildergui, but can't find that posted either.
Thanks,
06/12/2007 (11:58 am)
Hey, MatthewI came across a post that was describing how to display a (say a health bar) that is full and depending on what is happening it would update the color bar. (Silly me) I forgot book mark the page. The post describe that you would make two GuiBitmapctrl. One with health bar full and the other one empty, and it also went on how to update the bar, but at last I can seem to find that posted.. I also believe it was mixed in with a simple modification to GuiEditor.ed.cs; so when you switch to GUI Builder and save it toggle backs to the levelbuildergui, but can't find that posted either.
Thanks,
#3
If you want I can give you some code on how to make HUD bars. One way is to use the GUI, though that is quite a GUI issue. Personally, I prefer to use static sprites for such a thing, they have much more functionality and are much easier to use. Let me know which method you'd prefer and I'll post some code if you so desire.
06/13/2007 (6:30 pm)
Keith,If you want I can give you some code on how to make HUD bars. One way is to use the GUI, though that is quite a GUI issue. Personally, I prefer to use static sprites for such a thing, they have much more functionality and are much easier to use. Let me know which method you'd prefer and I'll post some code if you so desire.
#4
Yes, I would be interested in seeing some coding examples if you code post them. Since, you prefer the static sprites method, I will go with that since it does seem the GUI way might be a little tricky. I'm open to any possible ideas.
Thanks Kevin
06/14/2007 (9:14 am)
Hey KevinYes, I would be interested in seeing some coding examples if you code post them. Since, you prefer the static sprites method, I will go with that since it does seem the GUI way might be a little tricky. I'm open to any possible ideas.
Thanks Kevin
#5
I took these examples from a project I'm working on. In it, a health bar and shield bar are mounted to the player and they shrink towards the center when the player is damaged. The whole shrinking towards the center is just what static sprites naturally do, you could probably make them shrink to just one side, but it would be a lot more work.
First, I setup some datablocks for the HUD bars. These are mainly for the blend color:
Notice that there is also a "ShieldBarBack". This is the background for the shield bar, so that you can tell what full shields would be. The image map is just a 5x5 white box.
Next, we create the actual bars:
Now we have a Shield bar.
Next, we must give the HUD some functionality. Use this function for when the player's shields are modified:
Lastly, we must define what "modifyWidth" is. This was the hard part:
First, this function checks to see whether the width of the object is between the goal + or - the increment. If so, it sets the width to goal, cancels and pending schedules and stops there. The rest is pretty self explanatory. You actually may be able to delete that last else statement, but I haven't tested that, so I don't know if it works.
Hope this helps.
06/18/2007 (5:31 am)
Sorry it took so long for me to respond, Keith, but I haven't forgotten!I took these examples from a project I'm working on. In it, a health bar and shield bar are mounted to the player and they shrink towards the center when the player is damaged. The whole shrinking towards the center is just what static sprites naturally do, you could probably make them shrink to just one side, but it would be a lot more work.
First, I setup some datablocks for the HUD bars. These are mainly for the blend color:
//Shield HUD bar
datablock t2dSceneObjectDatablock(ShieldBarDatablock)
{
imageMap = boxImageMap;
class = hudBar;
Layer = 0;
GraphGroup = 0;
size = "6.5 0.714";
BlendColor = "0 173 255 0.4";
WorldLimitCallback = true;
WorldLimitMode = CLAMP;
WorldLimitMin = "-50 -37.5";
WorldLimitMax = "50 37.5";
maxWidth = 6.5;
maxAlpha = 0.4;
};
//Background of shield HUD bar
datablock t2dSceneObjectDatablock(ShieldBarBackDatablock)
{
imageMap = boxImageMap;
class = hudBar;
Layer = 0;
GraphGroup = 0;
size = "6.5 0.714";
BlendColor = "0 0 0.8 0.45";
WorldLimitCallback = true;
WorldLimitMode = CLAMP;
WorldLimitMin = "-50 -37.5";
WorldLimitMax = "50 37.5";
};Notice that there is also a "ShieldBarBack". This is the background for the shield bar, so that you can tell what full shields would be. The image map is just a 5x5 white box.
Next, we create the actual bars:
function Player::InitializeHUD(%this)
{
//------------------------------------------------------
//SHIELD BAR
%this.shieldBar = new t2dStaticSprite()
{
scenegraph = sceneWindow2D.getSceneGraph();
config = ShieldBarDatablock;
};
%this.shieldBar.setName("shieldBar");
%this.shieldBar.mount(%this, "0 1.5", 0, false, true);
%this.shieldBarBack = new t2dStaticSprite()
{
scenegraph = sceneWindow2D.getSceneGraph();
config = ShieldBarBackDatablock;
};
%this.shieldBarBack.setName("shieldBarBack");
%this.shieldBarBack.mount(%this, "0 1.5", 0, false, true);
}Now we have a Shield bar.
Next, we must give the HUD some functionality. Use this function for when the player's shields are modified:
//Updates the width of the shield bar
function Player::updateShieldBar(%this)
{
%ratio = (%this.shield/100);
%goal = (%ratio * %this.shieldBar.maxWidth);
%this.shieldBar.modifyWidth(0.1, 50, %goal);
}Lastly, we must define what "modifyWidth" is. This was the hard part:
//This function changes the object's width to match a goal
function t2dSceneObject::modifyWidth(%this, %increment, %speed, %goal)
{
if((%this.getWidth() > (%goal - %increment)) && (%this.getWidth() < (%goal + %increment)))
{
%this.setWidth(%goal);
if(isEventPending(%this.modSchedule))
cancel(%this.modSchedule);
return;
}
if(!isEventPending(%this.modSchedule))
{
if(%this.getWidth() > %goal)
{
%this.setWidth(%this.getWidth() - %increment);
if(!isEventPending(%this.modSchedule))
%this.modSchedule = %this.schedule(%speed, "modifyWidth", %increment, %speed, %goal);
return;
}
else if(%this.getWidth() < %goal)
{
%this.setWidth(%this.getWidth() + %increment);
if(!isEventPending(%this.modSchedule))
%this.modSchedule = %this.schedule(%speed, "modifyWidth", %increment, %speed, %goal);
return;
}
else
cancel(%this.modSchedule);
}
}First, this function checks to see whether the width of the object is between the goal + or - the increment. If so, it sets the width to goal, cancels and pending schedules and stops there. The rest is pretty self explanatory. You actually may be able to delete that last else statement, but I haven't tested that, so I don't know if it works.
Hope this helps.
Torque 3D Owner Matthew Langley
Torque