Game Development Community

Gui In Txb 2.0

by Louis-Philippe Dallaire · in Torque X 2D · 04/04/2008 (8:06 pm) · 4 replies

Hi!
I've been toying around with TXB for a few days now, and I have yet to figure out a way to use the GUI classes to build my UI. I know now that TXB doesn't come with the GUI Editor (which is a real shame), so is there any good example/tutorial around that could help me?

For example, how do I display a simple "Hello World" string that would appear on the top-right corner of my screen?

Note: I did read the doc, but it has not been very helpful.

#1
04/22/2008 (7:11 pm)
I thought someone might be interested on how I ended up doing my "Hello world" gui string. This is displayed in the top left corner though.

GUIMLText m_text;
GUIControl m_root;

...

void InitGUI()
{
GUIStyle rootStyle = new GUIStyle();
rootStyle.IsOpaque = false;

GUIMLTextStyle bodyStyle = new GUIMLTextStyle();
bodyStyle.Alignment = TextAlignment.JustifyLeft;
bodyStyle.TextColor[CustomColor.ColorBase] = Color.White;
bodyStyle.SizeToText = true;
bodyStyle.AutoSizeHeightOnly = false;
bodyStyle.FontType = "Arial12";

// init gui controls
m_root = new GUIControl();
m_root.Style = rootStyle;
m_root.HorizSizing = HorizSizing.Width;
m_root.VertSizing = VertSizing.Height;
m_root.Size = new Vector2(GUICanvas.Instance.Size.X, GUICanvas.Instance.Size.Y);

m_text = new GUIMLText();
m_text.Style = bodyStyle;
m_text.HorizSizing = HorizSizing.Relative;
m_text.VertSizing = VertSizing.Relative;
m_text.Size = new Vector2(400.0f, 20.0f);
m_text.Visible = true;
m_text.Folder = m_root;
m_text.Text = "Hello World";

GUICanvas.Instance.PushDialogControl(m_root, 99);

}
#2
04/22/2008 (7:40 pm)
You can also use .gui XML files. Check out the TankBuster demo (\data\ui folder) for some example screens and the demo code for how to load and display them. That way you can change the GUI and play around with it without rebuilding your project.
I used fixed sizing (locations) rather than setting everything to Relative. It makes it a little easier to make sure they stay where I put them.

--Tom
Starlit Sky Games
#3
04/22/2008 (7:51 pm)
That is indeed very good to know :) thank you!
#4
05/30/2008 (9:30 am)
How on earth did you ever figure this out?