Game Development Community

Couple questions on TDN Strategy Tutorial

by Mike Lilligreen · in Torque Game Builder · 01/22/2006 (4:16 am) · 9 replies

Hello,

I guess most of these questions are directed at Matthew, but if anyone else has some insight for a novice scripter please feel free to share.

1. After completing the BasicGameGUI section, selecting my base did not bring up the BaseMenu GUI. I think the problem is in the SingleSelection() function. Is %obj.onSelected(%pos) calling t2dSceneObject::onSelected (which is still an empty function) instead of Base::OnSelected? I put in an echo for %obj in the single selection function as well and selecting my base returns a number like 1814. Shouldn't it be instead CirclesBase or something similar?

I've gotten around the problem for the moment by just calling base.onSelected in SingleSelection but of course any object selected will cause the GUI to pop up.

2. I understand you dont have enough time to tutorialize the camera section, but playing with the code posted has been interesting. When I first ran the tutorial after putting in all the code, moving the mouse to the edge of the window didnt do anything and the console was spammed with a lot of t2dSceneObject::setArea() - invalid number of parameters. Eventually moving the mouse around a bunch caused the camera scrolling to suddenly "kick in".

I uncommented $cameraPos = getCameraPos(); in the initCamera function and that got rid of setArea spam and the camera works right away but also was zooming in along with scrolling. There were a few ways to fix the zooming but I settled on using setTargetCameraPosition(%x, %y) instead of ($cameraPos) in PanAction, which left all the width/height stuff in $cameraPos to take of the camera world boundries as I think you intended.

Anyway, my question for this section: is there any way to stop the camera from scrolling when I am over the upper/lower menu GUIs? I thought the getIsWindowPoint function might do the trick but I couldn't get it to work.

Thank you for these tutorials by the way, they've been a big help in learning how T2D works.

#1
01/23/2006 (11:01 am)
1. You are completely correct... thanks for catching this, I forgot to add that you need to add a single line to you t2dSceneobject::onSelected() function... like this

// --------------------------------------------------------------------
// t2dSceneObject::onSelected()
//
// This is the function all objects pass through when selected
// it places the description text that comes directly from the object
// and places it into a temporary GUI that gets attached to the 
// description section of the Object Properties box
// --------------------------------------------------------------------
function t2dSceneObject::onSelected(%this, %pos)
{
   %this.type.onSelected(%this, %pos);
}

That tutorial and the last post of code (which hasn't been tutorialized) I posted when I ran out of time, had to work on other fun and exciting things here at GG (its T2D stuff though :).
#2
01/23/2006 (11:06 am)
2. Once I get a moment I'll rescan through the scripts, I posted them up pretty quickly though I want to make sure I have all of it up there, I probaby forgot a single line or two like you found in the last one...

In response to whether or not you can stop the camera from scrolling if you move to your menus... definately yes... in fact its as simple as adding these two callbacks for your SceneWindow...


// --------------------------------------------------------------------
// SceneWindow2D::onMouseEnter()
//
// This function is triggered from the engine when the mouse enters the screen
// --------------------------------------------------------------------
function SceneWindow2D::onMouseEnter(%this, %modifier, %worldPos, %mouseClicks)
{
   // when we enter the screen we want to re move the mouseLeftGui warning
   mainScreenGui.remove(mouseLeftGui);
   // enable camera panning with a delay so we don't pan as we move in from 
   // outside the game window
   schedule(300, 0, "enablePan");
}

// --------------------------------------------------------------------
// SceneWindow2D::onMouseLeave()
//
// This function is triggered from the engine when the mouse leaves the screen
// --------------------------------------------------------------------
function SceneWindow2D::onMouseLeave(%this, %modifier, %worldPos, %mouseClicks)
{
   // generate the mouse left gui to warn us our mouse has left
   // this is mainly for debuging purposes
   new GuiMLTextCtrl(mouseLeftGui) { 
      text = "MOUSE LEFT"; 
      extent = "50 50";
      position = "350 10";
   };

   // add the control
   mainScreenGui.add(mouseLeftGui);

   // stop all panning of the camera so the camera isn't constantly moving
   // while we're out of the game wi
   stopAllPanning();
   
   // here we check each panning direction, if we're panning then we stop panning
   if($panningLeft)
   {
      stopPanning(Left);      
   }
   
   if($panningRight)
   {
      stopPanning(Right);      
   }
   
   if($panningUp)
   {
      stopPanning(Up);      
   }
   
   if($panningDown)
   {
      stopPanning(Down);      
   }
   
   // here we disable panning while we're out of the window
   disablePan();
}
#3
01/23/2006 (11:07 am)
You can take out the part where I create a little GUI control and add it to the main screen, I used it as a test and a reminder that my mouse was leaving the scene window
#4
01/23/2006 (11:08 am)
To fix the camera issue try commenting $cameraPos = getCameraPos(); out again... and change your setupT2DScene() in your client.cs to this

// --------------------------------------------------------------------
// Setup T2D Scene.
// --------------------------------------------------------------------
function setupT2DScene()
{
	// Create t2dSceneGraph.
	new t2dSceneGraph(t2dScene);
	
	// Associate Scenegraph with Window.
	sceneWindow2D.setSceneGraph( t2dScene );
	
	// Set Camera Position to be centered on (0,0) with
	// view width/height of (100/65).
      $cameraPos = "0 0 100 65";
	sceneWindow2D.setCurrentCameraPosition( "0 0 100 65" );

	
	// ************************************************************************
	//
	// Add your custom code here...
	//
	// ************************************************************************
	
	onStartUp();
}
#5
01/23/2006 (3:16 pm)
Btw keep the feedback coming, I really appreciate it :)
#6
01/25/2006 (9:57 am)
Everything works great now, thanks. :)

Will you be coming back at some point to complete the tutorial series or have you moved on to greener T2D pastures and it's up to the community now?

As for additional feedback: writing style, format, code breakdown and explainations are great, very easy to follow and understand. Wouldnt change a thing there.

Now that alpha3b uses the new file setup and client.cs changed names, your game.cs might need to be changed. I've put everything that was in game.cs into actions.cs and have had no problems.

One thing with the genre tutorials in general (not specific to the strategy tutorial) is that there is very little mentioned anywhere for music/sounds. Obviously with a bit of site searching and looking at the scroller demo, I found out that T2D uses TGE's audio system and figured out how one would add that in. Most novice users of T2D, who might also not have a license to TGE (like me), could get a bit lost/confused when they get to the point of wanting to add music or sound effects. I know TDN will take care of this at some point, but I just wanted to point that out for those who enjoy creating genre tutorials. :) In the meantime, perhaps all the audio fields/properites could be added at some point to the reference pdf?
#7
01/25/2006 (2:40 pm)
Ok, in a bit of proactiveness, I added a basic tutorial for music and sound effects to the T2D page:

tdn.garagegames.com/wiki/Torque_2D/StandardTutorials/Basics/Music
#8
01/28/2006 (4:56 am)
Another question if you all dont mind.

I wanted to replace the team Circles with something a bit more generic: Team1. I used torsion to find all instances of the word circle in my project, then replaced them with Team1. Selecting my base causes the game to crash to desktop on the t2dSceneObject::OnSelection function.

Ok, I went back a replaced Team1 with Team thinking maybe I couldnt have a number in there. Crash to desktop again. Went back and replaced Team with Group. Crash to desktop again. Went back and replaced Group with Dogs. Things work fine just like Circles.

So I was wondering, do we have to always use "colorful" names for our ScriptObjects since stuff like team gets used for variables within it?

Thanks for your help.
#9
01/28/2006 (7:58 am)
Nevermind, figured out what was causing the crash. In this line from data.cs:

gameData.circles.base = gameData.spawnObject(CirclesBase, circles, "75 -77", "CircleBase");

If %type (CirclesBase) and %name ("CircleBase") happen to be the same, so for example I change %name to "CirclesBase" as well, then the OnSelection callback will bug out. Oh well, learned something today at least. :)