Problems with action map
by Darren Stuart · in Torque Game Builder · 03/31/2005 (5:59 am) · 5 replies
I am working on the tutorial.
I have put all the code upto playerUpStop() function into setupT2DScene() function.
I have tried with the functions out of the setupT2DScene() function but it will not move the ship if I press W at all.
heres the code.
// --------------------------------------------------------------------
// Setup T2D Scene.
// --------------------------------------------------------------------
function 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" );
// ************************************************************************
//
// Add your custom code here...
//
// ************************************************************************
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();
function playerUp()
{
// Set the player moving up.
$player.setLinearVelocityY( -$10 );
}
function playerUpStop()
{
$player.setLinearVelocityY( 0 );
}
}
I have put all the code upto playerUpStop() function into setupT2DScene() function.
I have tried with the functions out of the setupT2DScene() function but it will not move the ship if I press W at all.
heres the code.
// --------------------------------------------------------------------
// Setup T2D Scene.
// --------------------------------------------------------------------
function 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" );
// ************************************************************************
//
// Add your custom code here...
//
// ************************************************************************
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();
function playerUp()
{
// Set the player moving up.
$player.setLinearVelocityY( -$10 );
}
function playerUpStop()
{
$player.setLinearVelocityY( 0 );
}
}
#2
03/31/2005 (6:07 am)
Ah thank you. It was driving me mad :p
#3
03/31/2005 (6:08 am)
No problem. Just glad I could help. =)
#4
Here is the code:
Any idea what I'm doing wrong here? THis code was based off the fish tutorial pdf file.
05/27/2006 (10:43 pm)
Okay, I've got a really confusing one, too. I'm trying to move the sprite left or right. It works fine with the keyboard, but not with the mouse.Here is the code:
function Player::onLevelLoaded(%this, %scenegraph)
{
$player = %this;
new ActionMap(moveMap);
moveMap.bindCmd(keyboard, "a", "playerLeftMove();", "playerLeftStop();");
moveMap.bindCmd(keyboard, "d", "playerRightMove();", "playerRightStop();");
moveMap.bindCmd(mouse0, "xaxis", "playerLeftMove();", "playerLeftStop();");
moveMap.push();
}
function playerLeftMove()
{
$player.setLinearVelocityX( -15 );
}
function playerLeftStop()
{
$player.setLinearVelocityX( 0 );
}
function playerRightMove()
{
$player.setLinearVelocityX( 15 );
}
function playerRightStop()
{
$player.setLinearVelocityX( 0 );
}Any idea what I'm doing wrong here? THis code was based off the fish tutorial pdf file.
#5
Change
to
then add this function
*note* I haven't tested that code, but I THINK it should work.
05/28/2006 (3:33 pm)
I don't think you can bind the xaxis like that. It's probably calling BOTH functions instead of just the one you want... Try something like this instead:Change
moveMap.bindCmd(mouse0, "xaxis", "playerLeftMove();", "playerLeftStop();");
to
moveMap.bindCmd(mouse0, "xaxis", playerXAxisCheck);
then add this function
function playerXAxisCheck(%val)
{
if (%val < 0)
{
playerLeftMove();
} else if (%val > 0)
{
playerRightMove();
} else
{
playerRightStop();
}
}*note* I haven't tested that code, but I THINK it should work.
Torque Owner Phillip "Renolc" Gibson
to
It was a typo in the tutorial. ;)