Game Development Community

Showing a scoreboard (GUIText)

by Dana Dill · in Torque X 2D · 04/25/2007 (11:00 pm) · 7 replies

Hi,

I am trying to display some text on the screen of the SpaceShooter example. As scoreboard. Here is the code:

GUITextStyle txtStyle = new GUITextStyle();
txtStyle.FontType = "arial16";
txtStyle.TextColor = Color.White;
txtStyle.HasBorder = true;
txtStyle.BorderColor = Color.Yellow;

GUIText _scoreboard = new GUIText();
_scoreboard.Style = txtStyle;
_scoreboard.Text = "00000";
_scoreboard.Layer = 0;
_scoreboard.Awaken();
_scoreboard.Position = new Vector2(WorldEdgeMin.X + 10, WorldEdgeMin.Y + 10);

But nothing shows on the screen when I start the game.

Can anyone see what I am doing wrong?

Thanks!

#1
04/25/2007 (11:37 pm)
One thing I can see is that you're not assigning your GUIText-control to any hierarchy. Meaning you have to set the GUIText.Folder to your GUISceneView or any other GUI hierarchy you want to render it with. Also, I don't remember right off, but you should check if the .Position is specified in the coordinates of the world (i.e. game objects), window (e.g. whole torgueX screen) or view (e.g. splitscreen coordinates)

Matias
#2
04/26/2007 (10:07 am)
The GUI system is a hierarchy, and at the root is the Canvas, which always exists. You push content to the Canvas to display it. Content would be a collection of one or more GUI controls and at the root of this collection is what I call the content control.. because it is by referring to this control that it gets added to the canvas.

Now, a GUIText control wouldn't be a good candidate for a content control, because its only text. However, the base class GUIControl is a good one, as well as GUIBitmap. So, how do you get a GUIText on the screen then?

Well you would create a content control first. This control would collect all controls that you wanted to display for a particular menu, screen, whatever. For instance, a main menu might consist of a GUIBitmap content control with GUIText, GUIButtons, etc as children (a part of its collection or hierarchy). Then when you wanted to display this main menu you would push the main menu control to the canvas thereby displaying it and all its children controls including the GUIText and GUIButtons.

One thing to remember though is the content control will always be the same size as the canvas. This is why GUIText would not make a good candidate for a content control, whereas a GUIBitmap would (to display a fullscreen background image for instance). Dialog controls will allow you to push content to the canvas that doesn't cover the entire canvas, but that is another topic for another time.

So, to get your GUIText control to the screen, you will have to do what Matias said in his post. You'll want to set the Folder property to the reference of the content control. Since you don't have one, you'll have to make it first. Once you do that, you can call Canvas.Instance.SetContentControl.

Some other things I noticed:

1) Don't call Awaken on a control. This is meant for the Canvas and should probably be made internal in the future to prevent people from calling it directly.

2) The GUI system uses a different coordinate system. Positions are relative to the parent control.
#3
04/26/2007 (10:17 am)
Excellent information! Thanks so much. I will redo my code with your suggestions.

I would enjoy hearing a detail explanation of the Dialog controls sometime. :)
#4
04/26/2007 (8:45 pm)
Also, you might need to set the .size property

ALSO, make sure you are using a GuiSceneView as your base gui container. You *must* use the guisceneview to show gui stuff plus your actual game at the same time. this isnt called out very explicitly most places, but it is definatly nessicary. (note: i havent looked at the spaceshooter demo, so it might already use the guisceneview)
#5
04/26/2007 (10:02 pm)
Thank you so much for all the help. I have made changes but I am still not seeing my text. Any suggestions?

GUIStyle playStyle = new GUIStyle();
GUISceneview play = new GUISceneview();
play.Name = "PlayScreen";
play.Style = playStyle;

GUITextStyle txtStyle = new GUITextStyle();
txtStyle.FontType = "arial16";
txtStyle.TextColor = Color.White;
txtStyle.HasBorder = true;
txtStyle.BorderColor = Color.Yellow;

GUIText score = new GUIText();
score.Folder = play;
score.Style = txtStyle;
score.Text = "000000000000";
score.Layer = 0;
score.Position = new Vector2(125, 100);

GUICanvas.Instance.SetContentControl(play);
#6
04/28/2007 (12:27 am)
Don't forget to set score.Visible = true and score.Folder = (whatever your top leve gui is)
#7
07/18/2007 (9:15 am)
You probably figured this out already, but you need to set a Size.