Game Development Community

TDN T2D suggestions

by Darren Stuart · in Torque Game Builder · 09/01/2005 (2:58 pm) · 25 replies

What would people like to see in the t2d part of the Torque developer network?

I would like some no fuss simple explainations of engine features.

heres my list

how to connect a gui to a game
how to use Torque script with a button
how to use Torque Script with a textbox

how to use the mouse object
drag and drop example

collision examples

simple platform game example: Tilemap with animated character jumping from a platform to another one. using gravity would be good.

simple dropping blocks puzzle game

attaching a camera to a player

tile mapping 101

networking games

particles 101

dummies guide to t2d physics

how to pack a game for publishing

complete list of all built in functions with a description of what they do and a simple sample code
Page «Previous 1 2
#1
09/01/2005 (3:20 pm)
I would be willing to write some of this stuff up. If people want to give some input on what would be the most useful, I can start there. I'm already planning a platformer example once I finish my current project (expect another .plan on this soon).

I can get this stuff on TDN and also release it here, depending on when TDN launches.
#2
09/01/2005 (3:40 pm)
That would be cool, The highest thing on my list is the Gui stuff. I really would like a solid simple example of connecting torque script to gui elements.
#3
09/02/2005 (12:46 pm)
Seems noone else is bothering to ask for stuff so I shall continue :P

compiling t2d with the tbe

creating objects in c++ that connect to torque
#4
09/02/2005 (1:28 pm)
Okay, quick tutorial on how to make GUI widgets do stuff in your T2D game.

These examples work on the standard example directory of Torque 2D.

Start up T2D.exe, hit F10 and create a new GUI (how to use the GUI editor is covered in a myriad places elsewhere). Create a new GUI, name it something like fooDlg. Create a new GuiWindowCtrl with a new GuiButtonCtrl. The GuiButtonCtrl has a field called "command", this is where you enter the command the button will execute when you click it. If you enter "doStuff();" as the command, the function doStuff() will be called.

Save the dialog as fooDlg.gui and move it somewhere relevant, say "T2D/client/". Then edit your "T2D/client/client.cs" (or whatever you wish) to load the .gui file. If you'll look at line 35 in client.cs you'll see how you execute script files (.gui files are really just regular script files). So just add this in there somewhere:

exec("./mainScreenGui.gui");

Then edit fooDlg.gui in a text editor. My fooDlg.gui looks like this:

//--- OBJECT WRITE BEGIN ---
new GuiControl(fooDlg) {
   profile = "GuiDefaultProfile";
   horizSizing = "right";
   vertSizing = "bottom";
   position = "0 0";
   extent = "640 480";
   minExtent = "8 2";
   visible = "1";

   new GuiWindowCtrl() {
      profile = "GuiWindowProfile";
      horizSizing = "right";
      vertSizing = "bottom";
      position = "171 125";
      extent = "182 87";
      minExtent = "8 2";
      visible = "1";
      text = "foo!";
      maxLength = "255";
      resizeWidth = "1";
      resizeHeight = "1";
      canMove = "1";
      canClose = "1";
      canMinimize = "1";
      canMaximize = "1";
      minSize = "50 50";

      new GuiButtonCtrl() {
         profile = "GuiButtonProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "22 37";
         extent = "140 30";
         minExtent = "8 2";
         visible = "1";
         command = "doStuff();";
         text = "Do Stuff!";
         groupNum = "-1";
         buttonType = "PushButton";
      };
   };
};
//--- OBJECT WRITE END ---

You could simply add your doStuff() function in the fooDlg.gui file to keep all the relevant foo code in one place. Append this snippet to fooDlg.gui:

function doStuff() {
	%foo = new fxStaticSprite2D() {scenegraph = t2dSceneGraph;};
	%foo.setImageMap(ringImageMap);
}

Now you have a guicontol that calls a function which in return executes some T2D stuff.
Now load up T2D. To push the fooDlg on to the canvas stack run this in the console

canvas.pushDialog(fooDlg);

This will bring up a window with a button you can click to create a ring in the middle of the screen. To pop the dialog off the stack you go

canvas.popDialog(fooDlg);

That's it. Easy as pie. Keep in mind, however, that much of this stuff belongs more to the gui sphere of the TGE platform, and isn't solely part of Torque 2D.

--
Hans
#5
09/02/2005 (1:36 pm)
Thanks Han your a star.
#6
09/02/2005 (1:52 pm)
Keep the suggestions coming :) I'm trying to make T2D TDN as straightforward as possible - at least the T2D TorqueScript part of it that I'm working on..

right now I have it set up like this (feel free to give me feedback)...

there are some basic getting started articles, then there are getting started articles for each genre, platformer, shooter, RTS, Puzzle, etc...

There are FAQ's divided up to sections for easy navigation.

A lot of this stuff I'll be working on this weekend and next week so feel free to give me input :)
#7
09/02/2005 (2:11 pm)
Just a short example on how to use the mouse callbacks to drag sprites around the scene.
In "T2D/client/client.cs" around where it says "Add your custom code here..." create a few sprites

for (%i = 0; %i < 20; %i++) {
	%foo = new fxStaticSprite2D() {scenegraph = t2dSceneGraph;};
	%foo.setImageMap(ggLogoImageMap);
	%foo.setPosition((getRandom() * 80)-40 SPC (getRandom() * 80)-40);
	%foo.setRotation(getRandom() * 360);
}

Then, at the end of the file, append these functions:

function sceneWindow2D::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks) {
	// Pick all the objects at the clickety point
	%list = t2dSceneGraph.pickPoint(%worldPosition);
	if (getWordCount(%list) > 0) {
		// Take the topmost one
		%target = getWord(%list,getWordCount(%list)-1);
		%target.setPosition(%worldPosition);
		$draggedObject = %target;
	}
}

function sceneWindow2D::onMouseDragged(%this, %modifier, %worldPosition, %mouseClicks) {
	if (isObject($draggedObject))
		$draggedObject.setPosition(%worldPosition);
}

function sceneWindow2D::onMouseUp(%this, %modifier, %worldPosition, %mouseClicks) {
	if (isObject($draggedObject))
		$draggedObject = NULL;
}

Okay, what happens here. Well, we create functions for the onMouseDown, onMouseDragged and onMouseUp callbacks which gets called when the relevant events trigger them.
In onMouseDown we see if there are any objects at the point we clicked. If there are, we take the first one, move it to the point we clicked and then set a global object to hold a pointer to the object.
Once we drag the mouse while the button is down, which triggers a whole bunch of onMouseDragged events. We continously move the object pointed to in the global object $draggedObject, to the position the mouse is.
Once we release the mouse, we clear the global object, thus we won't drag anything if we, later, clicked and dragged in the empty "air".

It's a short and quick solution, however it's not as elegant, what with the object clicked on, is directly moved to the point we clicked. You could solve that with mounts and such. Have fun experimenting with that.

--
Hans
#8
09/02/2005 (2:19 pm)
Nice, I'd love to see some RTS/Platformer resources for T2D...

After seeing the RTS Kit for TGE, I'm blown away by the possibility of a similar product for T2D... Hey, I'm allowed to wish, right? :)

P.S. Ah, Hans, that above example rocks, thanks!
#9
09/02/2005 (2:47 pm)
Lol wishing is good, in the past I had considered doing an RTS kit for T2D and even talked with Josh and Melv about kits, though they had some very real concerns that the codebase might be changing so much that its hard to do it at this point. They still liked the idea and liked the idea of preparing ahead of time :) No promises on whether I'll follow through or whether not it makes sense in the future though.
#10
09/02/2005 (3:01 pm)
Btw if you haven't seen these already they're a great place to start with T2D.
#11
09/02/2005 (3:10 pm)
NICE! I'm downloading those immediately. Thanks!
#12
09/03/2005 (11:33 am)
Hey Matt, thanks alot for those those tutorials. They rock, period. Hehe... :)
#13
09/05/2005 (2:55 am)
Just thought file access stuff would also be useful
#14
09/05/2005 (12:54 pm)
Active Tiles examples & documentation!
#15
09/06/2005 (12:40 am)
Also- using T2D sprites instead of regular GUI objects.
#16
09/06/2005 (12:42 am)
Quote:Also- using T2D sprites instead of regular GUI objects.

Maybe detailing something like this?
#17
09/06/2005 (1:05 am)
@Matt- like that. thank you

Something else on my wishlist for the docs is fxAnimatedSprite. I can't figure out how to use them from The T2DReference.pdf (datablock, controller, datablock. etc. etc.) , it's not used in either the spaceshooter or fish demos, nor in Matthew's original 10 tutorials.

I feel like I must be overlooking some real obvious explanation of fxAnimatedsprites.
#18
09/06/2005 (1:09 am)
Here is a thread about it, which links back to my T2D unofficial FAQ, though the FAQ hasn't been updated in a while.
#19
09/06/2005 (9:56 pm)
@Matthew- thank you again!
#20
09/10/2005 (4:16 pm)
Mostly I just want to see TDN as soon as possible and don't care if it's complete or not. I read it was supposed to launch in mid august. Any news?

Currently the T2D docs are in a few pdfs here, T2D html tutorials there, and the TGE GUI docs are on the site, the Torquescript docs over there, Engine docs over here. Makes my head spin. I would die for a 1-stop easy to navigate set of documentation for torque.
Page «Previous 1 2