Game Development Community

Text doesn't show

by rwillis · in Torque X 2D · 08/14/2007 (8:47 pm) · 4 replies

I've created GUIText objects but for some reason I can't get any text to show. I've tried chaning the folder and putting the GUIText object in another class but it still doesn't show up. MY GUIBitmap below (bar) shows and so does all the other GUI stuff I've done, but I just can't get text. Is there something special I have to do to get text? Note: Also, I can see the text in TankBuster

Here's the code:

class GamePlayGUI: GUIBitmap, IGUIScreen
{
static GUISceneview sceneview;
GUIStyle viewStyle;
GUITextStyle textStyle;
GUIText text;

static public GUISceneview Sceneview
{
get { return sceneview; }
}


public GamePlayGUI()
{
int gamepadId = InputManager.Instance.FindDevice("gamepad0");
int keyboardId = InputManager.Instance.FindDevice("keyboard");

GUIBitmapStyle backgroundStyle = new GUIBitmapStyle();
backgroundStyle.SizeToBitmap = false;
backgroundStyle.PreserveAspectRatio = false;
//backgroundStyle.Anchor = AnchorFlags.All;

// Create the GUISceneview
viewStyle = new GUIStyle();
viewStyle.PreserveAspectRatio = true;
viewStyle.Anchor = AnchorFlags.All;

sceneview = new GUISceneview();
sceneview.Name = GUIStateMachine.GamePlayGUIName;
sceneview.Style = viewStyle;
sceneview.Size = new SizeF(1024, 768);

GUIBitmap bar = new GUIBitmap();
bar.Bitmap = @"data\images\infoBox";
bar.Visible = true;
bar.Style = backgroundStyle;
bar.Folder = Sceneview;
bar.Size = new SizeF(1024, 128);
bar.Position = new Vector2(0, 668);

textStyle = new GUITextStyle();
textStyle.SizeToText = true;
textStyle.FontType = "arial16";
textStyle.TextColor = Color.Black;
textStyle.Anchor = AnchorFlags.All;
textStyle.Alignment = TextAlignment.JustifyCenter;

text = new GUIText();
text.Text = "TESTTEXT!";
text.Visible = true;
text.Folder = Sceneview;
text.Style = textStyle;
text.Position = new Vector2(100, 100);
}

#1
08/15/2007 (8:42 am)
You need to specify a size for your guitext control.
#2
08/15/2007 (9:45 am)
Alright, I added the size here:

text = new GUIText();
text.Text = "TESTTEXT!";
text.Visible = true;
text.Folder = Sceneview;
text.Style = textStyle;
text.Position = new Vector2(100, 100);
text.Size = new SizeF(50,20);


But I still don't get text.. In tankbuster they don't specify size here so I didn't think you had to. Or are you talking about some place else? BTW, that small bar i'm also loading is the only other bitmap on screen, and I still don't get text if I take it out (just in case someone's wondering if it might be covering the text up or something)
#3
08/15/2007 (5:06 pm)
I had a problem with something not showing up and it turned out it had a default size of 0,0 so thats why I suggested it. I don't see a size / position / visibility setting for the GamePlayGUI itself, although did you say the bitmap IS showing up? That would imply the GamePlayGui is at least set up properly. Just throwing out another idea here, do you want the text and bitmap folder to be the sceneview or the gameplaygui? How are you getting these onscreen, GUICanvas.SetContent(GamePlayGUI) or GUICanvas.SetContent(GamePlayGui.sceneview) ? (Possible typo on my part, setcontent or setcontentdialog..)
#4
08/15/2007 (8:48 pm)
Alright, I fixed it.

All I did was move the .text property to the bottom like this:

text = new GUIText();
text.Visible = true;
text.Folder = Sceneview;
text.Style = textStyle;
text.Position = new Vector2(100, 100);
text.Size = new SizeF(50,20);
text.Text = "TESTTEXT!";

instead of how I had it before which was like this:

text = new GUIText();
text.Text = "TESTTEXT!";
text.Visible = true;
text.Folder = Sceneview;
text.Style = textStyle;
text.Position = new Vector2(100, 100);
text.Size = new SizeF(50,20);

It could have taken me forever to figure that one.

Thanks for your help man.