Game Development Community

Need help with order of code in client.cs

by Colleen Monahan · in Torque Game Builder · 03/10/2005 (11:22 am) · 3 replies

I am running thru the basic tutorial and got hung up on getting the code to run for my player up (using 'w'). It would be helpful if the final code for the tutorial could be seen. I want to be sure I am placing things in the correct order/location.

This is my current code. Thanks.



unction setupT2DScene()
{
// Create fxSceneGraph2D.
new fxSceneGraph2D(t2dSceneGraph);

// Associate Scenegraph with Window.
sceneWindow2D.setSceneGraph( t2dSceneGraph );

// Set Camera Position to be centered on (0,0) with
// view width/height of (100/80).
sceneWindow2D.setCurrentCameraPosition( "0 0 100 75" );


}


// ************************************************************************
//
// MY custom code FOLLOWS...
//
// ************************************************************************



// --------------------------------------------------------------------
// Here we define movement for the player -----CM
// --------------------------------------------------------------------

function playerUp()
{
// Set the player moving up.
$player.setLinearVelocityY( -$10 );
}



// set up the first player
datablock fxImageMapDatablock2D(playershipImageMap)
{
mode = full;
textureName = "~/client/images/playerShip";
};
$player = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
$player.setPosition("-35 0");
$player.setSize( "14 7" );
$player.setImageMap( playershipImageMap );


// set up the enemy
datablock fxImageMapDatablock2D(enemyship1ImageMap)
{
mode = full;
textureName = "~/client/images/enemyship1";
};
%enemy = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
%enemy.setSize( "14 7" );
%enemy.setPosition("40 0");
%enemy.setImageMap( enemyship1ImageMap );

// move the enemy towards us.
%enemy.setLinearVelocityX(-20);


// Create a new action map.
new ActionMap(playerMap);
// Bind keys to actions.
playerMap.bindCmd(keyboard, "w", "playerUp();", "playerUpStop();");
playerMap.bindCmd(keyboard, "s", "playerDown();", "playerDownStop();");
playerMap.bindCmd(keyboard, "a", "playerLeft();", "playerLeftStop();");
playerMap.bindCmd(keyboard, "d", "playerRight();", "playerRightStop();");
playerMap.bindCmd(keyboard, "space", "playerFire();", "");
// Activate the action map.
playerMap.push();

#1
03/10/2005 (1:11 pm)
Colleen,

I apologise for the confusion but this problem has now been fixed and will be in the next update...

function playerUp()
{
// Set the player moving up.
$player.setLinearVelocityY( - );
}
... should be ...
function playerUp()
{
// Set the player moving up.
$player.setLinearVelocityY( -10 );
}

e.g. remove the "$" symbol from the "-$10" to give "-10".

This was a typo in the tutorial and has caused some confusion.

Sorry about this.

- Melv.
#2
03/10/2005 (1:47 pm)
Do you have a copy of the final code created with this tutorial? It would really help. Thanks!
#3
03/10/2005 (1:50 pm)
Jason Cahill posted his final tutorial code here: www.garagegames.com/mg/forums/result.thread.php?qt=26591