Game Development Community

Trying to set up a HUD (using the GUI Starter Kit)

by Matt Delph · in Torque X 2D · 08/27/2010 (1:56 am) · 4 replies

As I was going through the Airplane tutorial, I hit a roadblock when it came to setting up the HUD. After searching around these forums, I've seen a lot of talk about creating a GUISceneView in XML format. That sounds way too hard compared to the way the airplane tutorial has it setup. Only problem is that the tutorial wants me to put it in the game.cs file, which would screw up the whole GUI starter kit. I've tried dropping this code (which is what they want me to put in game.cs at the end of BeginRun)in the GUIplay class, but it gives me this error about line 2.

"Cannot inplicity convert type 'GarageGames.Torque.Core.TorqueBase' to 'GarageGames.Torque.T2D.T2DSceneCamera'. An explicit conversion exists (are you missing a cast?)"
// create and register a camera for the compass
T2DSceneCamera DefaultCamera = TorqueObjectDatabase.Instance.FindObject("Camera");
if (DefaultCamera != null)
{
    T2DSceneCamera InstrumentCam = (T2DSceneCamera)DefaultCamera.Clone();
    TorqueObjectType instrument = TorqueObjectDatabase.Instance.GetObjectType("instrument");
    TorqueObjectDatabase.Instance.Register(InstrumentCam);

    // display the instrument camera on screen
    GUIStyle InstrumentStyle = new GUIStyle();
    GUISceneview InstrumentView = new GUISceneview();
    InstrumentView.Style = InstrumentStyle;
    InstrumentView.Camera = InstrumentCam;
    InstrumentView.RenderMask = instrument; // only render objects of type "instrument"
    InstrumentView.Visible = true;
    InstrumentView.Folder = WorldView;
    InstrumentView.Bounds = new GarageGames.Torque.MathUtil.RectangleF(0.0f, 0.0f, 1024.0f, 768.0f);

I'm pretty sure there's a way to make this work in the GUIPlay class (I have a hard enough time playin' around with this stuff, I don't want to screw around with XML just yet), but after a few hours of tinkering, I figured I'd ask you guys. Any help is greatly appreciated.

#1
08/28/2010 (12:14 am)
Check this out. I can't remember where I found it but the author is in there somewhere, props to him.

It's a pretty in depth tutorial for GUI, code and XML. It really got me off the ground.

Here

Use the "save link as" or "save target as", clicking on it (at least for me) goes to the coding of the pdf.
#2
08/28/2010 (1:24 am)
The problem I have with the XML is that I would have to load the XML file instead of the txscene file. Another problem is that the "Introduction to the Torque X GUI" tutorial is that it doesn't mention anything about loading a T2DSceneObject as part of the HUD (instead of a static sprite).

The other thing that's confusing me is that near the end of Step 6 of this tutorial, it describes the exact thing I'm looking for. The only problem is I can't figure out how to get it to work in the 'TorqueX GUI 2D" template, instead of the blank "Starter Game 2D" template. The only thing I figured out, is that the code belongs in the GUIplay class, but I'm not sure what I have to change to make it work in there.
#3
08/28/2010 (4:23 pm)
Are you getting any kind of errors or is it just plain not working?

Off the top of my head it might not be working because TX3.1.5's builder doesn't save the camera name as "camera" anymore. So, when you clone the camera here:
T2DSceneCamera DefaultCamera = TorqueObjectDatabase.Instance.FindObject("Camera");

It's skipping the rest because that would return null.

As far as loading an xml file instead of a .txcene goes, you can load more than one thing at a time. I've usually got an xml for my HUD, a .txscene with my player and templates loaded up so they persist and another .txscene with the actual scene I'm playing in.
#4
08/28/2010 (7:39 pm)
Okay, I figure out how to make the HUD work by putting this code in my CameraComponent, which is attached to my plane.
// create and register a camera for the compass
            if (cam != null)
            {
                T2DSceneObject HUDCam = (T2DSceneObject)cam.Clone();
                TorqueObjectType HUD = TorqueObjectDatabase.Instance.GetObjectType("HUD");
                TorqueObjectDatabase.Instance.Register(HUDCam);

                // display the instrument camera on screen
                GUISceneview HUDView = new GUISceneview();
                GUIStyle HUDStyle = new GUIStyle();
                HUDView.Style = HUDStyle;
                HUDView.Camera = HUDCam as T2DSceneCamera;
                HUDView.RenderMask = HUD; // only render objects of type "instrument"
                HUDView.Visible = true;
                HUDView.Folder = GUICanvas.Instance;
                HUDView.Bounds = new GarageGames.Torque.MathUtil.RectangleF(0.0f, 0.0f, 1024.0f, 768.0f);
            }

Now the only thing I have left to figure out is where to put this.
NoRenderMask = HUD
All I know is that it has to be attached to the default GUISceneView, but I can't figure out where that is.