Game Development Community

T2D Gui Tutorial - A Starter

by Matthew Langley · 03/20/2005 (10:38 pm) · 15 comments

I recently created this Torque 2D Tutorial ... about the last 80% of it covers GUI controls... (so if you don't know how to use them yet)... - this covers some much more advanced GUI methods... this is just a primer for adding images as buttons


first go to where you have your images... make four copies of it... add _n to the end of one... _h to the end of another, _d to another and then _i to the end of the last... (_n = normal, _h = highlighted, _d = depressed, _i = inactive)

something like this

www.razedskyz.com/games/torque/tutorials/T2D/basicGUI/basicGui4.JPG
ok now fire up T2D... hit "F10"... go to the top Left and click File -> New GUI

www.razedskyz.com/games/torque/tutorials/T2D/basicGUI/basicGui1.JPG
in there choose a name for it... (best to keep some sort of naming standard)

now click on "GuiControl"...
www.razedskyz.com/games/torque/tutorials/T2D/basicGUI/basicGui2.JPGnow heres where you can choose what you want, if you want it to be a small menu that pops up (with the game in the background, keep it as GuiControl)... if you want the background to be an entire image from something else, go to guiBitmapCtrl...) now click ok

in here click on "New Control" go down to "GuiBitmapButtonCtrl" and click it...

www.razedskyz.com/games/torque/tutorials/T2D/basicGUI/basicGui3.JPGbring out more towards the center a bit... now in the right-bottom properties list click on "Expand All"... got down to bitmap

here type in the path to the image... mine was "T2D/client/buttons/gglogo"
note do this withou the _n, _h, or _d... it automatically adds those in at the right time... now click apply... you should see the image... this is what I see


now (after resizing mine some, click the button and then the black handles to resize)... go to the "command" property in the properties list... type "echo("test button press");" in there...

www.razedskyz.com/games/torque/tutorials/T2D/basicGUI/basicGui5.JPG

now click apply again...

note: if you kept your main control as GuiControl when we test this out you will get some weird background effects (only because the background is invisible so when you load this menu in game it will show the game in the background), if you chose to make the main control a bitmapCtrl... then you need to set a bitmap path for it also (the same way you did for the button)

hit "F10"... ignore any weird artifacts (since it has no background it doesn't refresh it...., just look for your image button and click it...

www.razedskyz.com/games/torque/tutorials/T2D/basicGUI/basicGui6.JPG
now bring up the console (with the "~" tilde key) and see if you see the echo text "test button press" like this

www.razedskyz.com/games/torque/tutorials/T2D/basicGUI/basicGui7.JPG
if you get this then it works... now to show you how this gui is really meant to perform...

hit "F10" again... go to File -> Save GUI ... click on the directory button like this

www.razedskyz.com/games/torque/tutorials/T2D/basicGUI/basicGui8.JPGgo down to T2D/client and click save

www.razedskyz.com/games/torque/tutorials/T2D/basicGUI/basicGui9.JPG
now hit the "~" tilde key and type in "quit();"
www.razedskyz.com/games/torque/tutorials/T2D/basicGUI/basicGui10.JPGand press enter...
now go to your T2D/client directory... open up "client.cs"

find all the statements that go like this "exec(./"

add one to the end like this

exec("./TestGui.gui");

(change the gui name to whatever you saved it as)... now save the file and close it... you should see the TestGui.gui (or whatever you named it) in that folder... if you want to change the command later, you can either do it in the editor or in the file itself... ok go fire up T2D

at the main screen hit the "~" tilde key... now type this

"canvas.pushDialog(TestGui);"

(make sure testGui is whatever you called the internal name... hit enter, and now you should see it overlayed... click it a few times and hit the console to see the text... to make the button dissapear type "canvas.popDialog(TestGui);" in the console... now in the command part you can put a script function if you want, so you can perform anything on clicks...

www.razedskyz.com/games/torque/tutorials/T2D/basicGUI/basicGui11.JPGwww.razedskyz.com/games/torque/tutorials/T2D/basicGUI/basicGui12.JPGto go back to editing this GUI hit "F10"

click the middle button up top
www.razedskyz.com/games/torque/tutorials/T2D/basicGUI/basicGui13.JPG
like this
www.razedskyz.com/games/torque/tutorials/T2D/basicGUI/basicGui14.JPGand go to your gui (mine I named TestGui)... here you can edit any of the already loaded GUIs...

Hope this helps... I strongly recommend going through the long tutorial I linked up top, but this will get you started :)

#1
03/20/2005 (10:37 pm)
Matthew, you seriously may be my new best friend
#2
03/21/2005 (2:04 pm)
Matt, you friggin rock. :)
#3
03/21/2005 (3:15 pm)
And for those wanting to see more on the gui editor, do a resource search for minapp. The tutorials were made to use with torque but can still be followed by T2D owners as the gui editors are the same.
#4
03/21/2005 (8:18 pm)
*LoTekK's eyes pop out of their sockets*

Good lord, KingBob. First an 80++ plage T2D tutorial, and now a dedicated GUI tutorial? You, sir, have entirely too much time on your hands. Not that that's a bad thing for us peons, mind you. ;)
#5
03/22/2005 (5:50 am)
Now do a tutorial on the Loading Bar or those Sliders
#6
03/22/2005 (6:29 am)
glad you enjoy... and Joe made a great suggestion to the minapp tutorials...

@LoTekK: lol... true, though sadly its not that I have too much time, I'm just a crazy insomniac lol, sunday spent about 5 hours on things, then spent about 5-6 hours on an animation project, hit the sack about 3:30... got up at 5:30 and started the day... fortunately I got more sleep last night though... glad you enjoy though.

@anthony: I still need to do a tutorial on the loading bar, however have an 80+ page tutorial encompassing the Physics Demo (which includes the sliders)
#7
03/22/2005 (12:08 pm)
Hello people,

Keep this poor soul alive as this is my first post :D. I followed this tutorial and noticed that the image path that Matthew refers to is slightly different.

I assume that the path is relative to the path where the compiled executable is put. Keeping that in mind i noticed that the subdirs T2d\client doesn't have a \buttons dir but a \images dir. I was sorry to find out that i cannot create a GuiBitMapButtonCtrl (General>Bitmap property is "T2D/client/images/ggLogo") and get it to show the .png file..

I get the gray message (warning i presume since it isn't red):

"Could not locate texture: T2D/client/images/ggLogo" a couple of times, each one with another sign like _n etc..

When i try the same with a GuiBitmapCtrl it immediately shows the image correctly. Any suggestions why i get this vague situation?

Thanks and i hope 2 become an active T2D developer as well :D

:: EeKay ::
#8
03/22/2005 (2:01 pm)
Feel free to post whenever you have any qustions :) Welcome to the community...

relook up at the first image... if you notice I copy and paste the ggLogo Image and add a "_n" and "_h" etc etc... make sure you have completed that step :)
#9
03/22/2005 (8:08 pm)
Thank you!
#10
03/23/2005 (9:09 am)
DOH!

2 fast 2 furious when i went over this tutorial.. i started reading @ "it will add the _n etc.. automatically".
I see it now and i also get the idea about the _n etc extensions.. Every bitmapbutton control has these states so they need to be represented by images.... makes sense to me!

I did it and i finally got through this tutorial without any pain haha!

@Matthew: Thanks! this is an welcome addition to the first summer day and my birthday :D

:: EeKay ::
#11
03/23/2005 (9:21 am)
Glad you made it through! :) Its always easy to miss simple things, especially in a hurry, I do it all the time lol... congrats on summer and your birthday!

if your up for another tutorial I created a much much larger one here
#13
07/20/2005 (3:11 am)
Thanks, Matt! This helped me make buttons for our game just now! :)
#14
09/09/2005 (9:25 am)
You can now get this tutorial along with 9 others in a T2D "Tutorial Pack"... in this pack each tutorial is an external html file so you can use them offline :)
#15
03/01/2006 (8:07 am)
None of the images show up.