GUI: What am I doing wrong?
by Trent · in Torque X 3D · 06/15/2009 (7:03 pm) · 8 replies
I really am trying to get a scene view with some text on it. So here is what I am doing. Can you tell me what I'm doing wrong?
private void CreateGui()
{
GUIControl root = new GUIControl();
root.Name = "root";
root.Style = new GUIStyle();
GUISceneview gui_scene = new GUISceneview();
gui_scene.Name = "myScene";
gui_scene.Folder = root;
gui_scene.Camera = CreateCamera();
GUITextStyle style = new GUITextStyle();
style.Name = "test_style";
style.FontType = "Arial16";
style.TextColor[CustomColor.ColorBase] = Color.White;
style.SizeToText = true;
GUIText text = new GUIText();
text.Name = "test";
text.Folder = gui_scene;
text.Text = "Hello";
text.Position = new Vector2(50, 20);
text.Style = style;
GUICanvas.Instance.SetContentControl(root);
}About the author
#2
I've tried a number of different methods to get a GUI happening and none have been successful. The closest I got was a text label on top of my guisceneview but it was centered vertically on the left side and I could not move it. I think that was when I pushed it as a Dialog though.
If you have something that works that you're willing to share, I'd be very grateful!
06/17/2009 (4:12 am)
If I run this I get a black screen.I've tried a number of different methods to get a GUI happening and none have been successful. The closest I got was a text label on top of my guisceneview but it was centered vertically on the left side and I could not move it. I think that was when I pushed it as a Dialog though.
If you have something that works that you're willing to share, I'd be very grateful!
#3
Let me know if that works for you
Gav
06/17/2009 (4:44 am)
Save this file and add it to a TX3D project (to test just create a Simple Starter Game 3D project. Onces its added, in your game.cs file add the following to your BeginRun function:guitest gt = new guitest(); GUICanvas.Instance.PushDialogControl(gt,0);
Let me know if that works for you
Gav
#4
However there is a catch that I forgot to mention, and it's a big one. I thought it didn't matter, but it must. I'm not using builder or XML levels at all. I'm doing everything in code. Builder is totally unusable for me (not to mention that my trial is now over) so I don't have much choice, but I also like seeing how these engines work.
So I am creating my GUISceneview in code but it seems that it works as soon as I create it. If I call SetControlControl(sceneview) the game crashes. So I push the dialog and yes I see the text (after I changed the colour to white!) but I no longer see the scene view. And this is as far as I have got so far.
After that I'm at a loss for what is going on without the source code.
06/17/2009 (3:06 pm)
That works fine.However there is a catch that I forgot to mention, and it's a big one. I thought it didn't matter, but it must. I'm not using builder or XML levels at all. I'm doing everything in code. Builder is totally unusable for me (not to mention that my trial is now over) so I don't have much choice, but I also like seeing how these engines work.
So I am creating my GUISceneview in code but it seems that it works as soon as I create it. If I call SetControlControl(sceneview) the game crashes. So I push the dialog and yes I see the text (after I changed the colour to white!) but I no longer see the scene view. And this is as far as I have got so far.
After that I'm at a loss for what is going on without the source code.
#5
06/17/2009 (3:14 pm)
Can have a look, I just created a basic starter game and dropped that on top and it worked, but thats loading a level from file. will try via code as well.
#6
06/17/2009 (3:22 pm)
Yeah it worked fine when I dropped it straight into a fresh starter game that loads from xml. That's why I have to wonder what I need to do to make my code setup the sceneview the same way the scene loader does.
#7
Does this mean HUD elements are meant to be added as dialogs rather than as child controls of the sceneview ala windows forms?
06/17/2009 (4:43 pm)
hmm correction to that, I think it does work. I disabled my player loading code in that test for some silly reason.Does this mean HUD elements are meant to be added as dialogs rather than as child controls of the sceneview ala windows forms?
#8
Maybe you could use the code I posted, but set the folder for the main GUIControl to be the Guicanvas or scene view? or setup so you can pass the parent of the Guicontrol into the contructor?
06/18/2009 (6:22 am)
Guess it could be done either way. Maybe you could use the code I posted, but set the folder for the main GUIControl to be the Guicanvas or scene view? or setup so you can pass the parent of the Guicontrol into the contructor?
Torque 3D Owner Gavin Beard
Byte Logic
I would normally create the gui via a seperate component (in this instance derived from GUIControl) then use this base control as the folder for all additional gui controls, then create a new instance of the component class in the main game and pop that to the front of the canvas. I have some code at home of a gui overlaid ontop of a 3d viewport, i shall post it later if it'll help?