Game Development Community

Problem with Getting Started/ObjectSelection1Tutorial

by Laralyn McWilliams · in Torque Game Builder · 01/12/2007 (2:30 pm) · 4 replies

I've been trying to debug why this isn't working, and I'm officially stumped. I'm to the point in this tutorial where you've got an image that is supposed to be on screen. I haven't even gotten to the part where you make it move yet.

tdn.garagegames.com/wiki/Torque_2D/Getting_Started/ObjectSelection1Tutorial

There are no errors in the console. I put an echo statement in the SimpleMouse function (the one that puts the object on screen) so I know that function is being executed.

Here's my game.cs:

//---------------------------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------
// startGame
// All game logic should be set up here. This will be called by the level builder when you
// select "Run Game" or by the startup process of your game to load the first level.
//---------------------------------------------------------------------------------------------
function startGame(%level)
{
   // Set The GUI.
   Canvas.setContent(mainScreenGui);
   Canvas.setCursor(DefaultCursor);
   
   moveMap.push();
   
   if( isFile( %level ) || isFile( %level @ ".dso"))
      sceneWindow2D.loadLevel(%level);
	

}

	//setup my player
	simpleMouse();
	
//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
   sceneWindow2D.endLevel();
   moveMap.pop();
}

And here's my simplemouse.cs:

function sceneWindow2D::onMouseMove( %this, %mod, %worldPos, %mouseClicks )
{
        if($debugMsg::mouse::callBacks)
                echo("Mouse Moving");

        //lets store the mouses position
        %this.mousePos = %worldPos;
}

function sceneWindow2D::onMouseDragged( %this, %mod, %worldPos, %mouseClicks )
{
        if($debugMsg::mouse::callBacks)
                echo("Mouse Dragging");

        //lets store the mouses position
        %this.mousePos = %worldPos;
}

function sceneWindow2D::onMouseDown( %this, %mod, %worldPos, %mouseClicks )
{
        if($debugMsg::mouse::callBacks)
                echo("Mouse Down");
}

function sceneWindow2D::onMouseUp( %this, %mod, %worldPos, %mouseClicks )
{
        if($debugMsg::mouse::callBacks)
                echo("Mouse Up");
}

function sceneWindow2D::onMouseEnter( %this, %mod, %worldPos, %mouseClicks )
{
        if($debugMsg::mouse::callBacks)
                echo("Mouse Entered... Knew it would come crawling back");
}

function sceneWindow2D::onMouseLeave( %this, %mod, %worldPos, %mouseClicks )
{
        if($debugMsg::mouse::callBacks)
                echo("Mouse Left... Go Get It!");
}

function simpleMouse()
{

        $test = new t2dStaticSprite() { sceneGraph = t2dScene; };
        $test.setImageMap( tileMapImageMap );
        $test.setSize( "5 5" );
        $test.setPosition( "0 0" );
        $test.isSelectable = true;
        $test.objectName = "test box";
		echo ("Simple Mouse executed");
}

That's the only scripting in the game right now, other than exec statements in main.cs.

Can anyone give me a hint about how to get $test to show up when I run the game?

Thanks! :)

#1
01/12/2007 (7:21 pm)
I have two things
In your simplemouse() function, try moving your ending curly brackets "}" to the end of thge t2dStaticSprite Creation like this... (May or may not fix your problem)
function simpleMouse()
{        
            $test = new t2dStaticSprite() 
            { 
             sceneGraph = t2dScene;
            $test.setImageMap( tileMapImageMap );
            $test.setSize( "5 5" );
            $test.setPosition( "0 0" );
            $test.isSelectable = true;
            $test.objectName = "test box";
            };
            
 echo ("Simple Mouse executed");}

}

The other thing I can think of is
Do you have an imageMap in your project named "tileMapImageMap" ?

If not, you need to create one in the leveleditor and name it that.
#2
01/12/2007 (10:41 pm)
I tried that change, and it caused a script error in the console.

If I add the next part of the tutorial, where it detects when you click on a sprite, and I manually add a sprite instead of using that simpleMouse code, it throws an error saying t2dScene isn't found.

Could it be that tutorial doesn't work in the latest release of TGB?
#3
01/13/2007 (4:38 am)
Instead of t2dScene, try sceneWindow2D.getSceneGraph().
#4
01/13/2007 (12:26 pm)
I had some sleep and realized what I had told you on that first part was wrong..
Usually it is done like this I think..

function simpleMouse()
{
                    $test = new t2dStaticSprite()
             {
              sceneGraph = sceneWindow2D.getscenegraph();
              ImageMap= "tileMapImageMap";
              Size = "5 5";
              Position = "0 0";
                          
            };

            $test.objectName = "test box";           
            $test.isSelectable = true;

 echo ("Simple Mouse executed");}
}
My previos post continued to use the functions to set the fields of the new sprite which was wrong.
You can set the fields of the sprite directly if you do it while creating the object like I am showing now.

objectname and isSelectable have to be referenced with the objectname ($test) in front and after the object is created because they are not t2dsceneobject or t2dStaticSprite fields default fields.

Note: I also added Marc's suggestion to the code above "sceneGraph = sceneWindow2D.getscenegraph();
"

I am new to TGB and when I create new sprites like the one above I always have been using scenegraph = %this) because I always pass it in from the calling function.