Game Development Community

Trouble creating new scenegraph for HUD

by Cryptwalker · in Torque Game Builder · 08/22/2006 (9:51 am) · 2 replies

Heya folks, from what I understand, the best way to create a HUD is to create a new scene graph and drop your HUD graphics on to it. However, I'm having some trouble getting the HUD to show up. Heres the code I'm using (BTW, what are the forum tags?):

new t2dSceneGraph(hudgraph)
{
extent = "640 480";
visible = "1";
};

function build_hud()
{
$Ammo = new t2dStaticSprite()
{
scenegraph = hudgraph;
};
$Ammo.setImageMap("AmmoImageMap");
$Ammo.setPosition(20,20);
}

I call it during the start up but nothing is loading. Did I do something incorrectly? Thanks for any help.

#1
08/22/2006 (4:11 pm)
AFAIK You need two Scene Windows on top each other, one for the GUI and one for the Game Area. So your GUI should look something like this:

new GuiChunkedBitmapCtrl(mainScreenGui) {
   canSaveDynamicFields = "0";
   Profile = "GuiContentProfile";
   HorizSizing = "width";
   VertSizing = "height";
   Position = "0 0";
   Extent = "1024 768";
   MinExtent = "8 8";
   canSave = "1";
   Visible = "1";
   bitmap = "~/data/images/logoblack";
   useVariable = "0";
   tile = "0";

   new t2dSceneWindow(sceneWindow2D) {
      canSaveDynamicFields = "0";
      Profile = "GuiContentProfile";
      HorizSizing = "width";
      VertSizing = "height";
      Position = "0 0";
      Extent = "1024 768";
      MinExtent = "8 8";
      canSave = "1";
      Visible = "1";
      lockMouse = "0";
      useWindowMouseEvents = "1";
      useObjectMouseEvents = "0";
   };
   new t2dSceneWindow(hudWindow2D) {
      canSaveDynamicFields = "0";
      Profile = "GuiContentProfile";
      HorizSizing = "width";
      VertSizing = "height";
      Position = "0 0";
      Extent = "1024 768";
      MinExtent = "8 8";
      canSave = "1";
      Visible = "1";
      lockMouse = "0";
      useWindowMouseEvents = "1";
      useObjectMouseEvents = "0";
   };
};

And then create your two scene graphs like this:

new t2dSceneGraph(t2dHudGraph)
{
   Extent = "1024 768";
   visible = "1";
};

new t2dSceneGraph(t2dSceneGraph)
{
   Extent = "1024 768";
   visible = "1";
};

And then assign the scene graphs to the respective windows:

sceneWindow2D.setSceneGraph(t2dSceneGraph);
hudWindow2D.setSceneGraph(t2dHudGraph);

I'm fairly sure that will allow you to display your HUD over your scene. I haven't done any testing on this, but it should work. I know I've read previously that you can assign multiple scenegraphs to the same window, so you may not need to set up two windows. The one thing I don't know, however, is how TGB handles the display order. I am assuming that TGB will render according the objects layer property not matter what scene window is dsiplayed, so you may want to make your GUI obects on the highest layer.
#2
08/22/2006 (8:14 pm)
Thanks for the detailed help Glenn, I will try it out.