Game Development Community

Working with different scenes in TGB

by Arden · in Torque Game Builder · 08/11/2010 (1:21 am) · 1 replies

Hello,

I'm trying to work from code a friend has left me which has a soldier image map move across the screen by pressing directions on the keyboard. My assignment is to go from there and create a new level to move him on.

So I went ahead by loading the project and created a new scene. I then went to the create tab, dragged the same soldier from the static sprites to the scene. I then made sure that the class was set to 'soldier', like it was in the original scene, but it's not working and I can't move him at runtime.

Is there something I must do in code to have it respond to player input when a diffent scene is loaded?
Or am I missing something in the editor?
I know it's kind a basic question, but any help would be appreciated.

Here is the code from the CS file:

function Soldier::onLevelLoaded(%this, %scenegraph)
{
$theSoldier = %this;

moveMap.bindObj(keyboard, "w", "Up", %this);
moveMap.bindObj(keyboard, "s", "Down", %this);
moveMap.bindObj(keyboard, "a", "Left", %this);
moveMap.bindObj(keyboard, "d", "Right", %this);
moveMap.bindObj(keyboard, "enter", "Enter", %this);
}

function Soldier::Up(%this, %pressed)
{
if ( %pressed )
{
%this.setLinearVelocityY(-%this.vSpeed);
}
else
{
%this.setLinearVelocityY(0);
}
}

function Soldier::Down(%this, %pressed)
{
if ( %pressed )
{
%this.setLinearVelocityY(%this.vSpeed);
}
else
{
%this.setLinearVelocityY(0);
}
}

function Soldier::Left(%this, %pressed)
{
if ( %pressed )
{
%this.setLinearVelocityX(-%this.hSpeed);
}
else
{
%this.setLinearVelocityX(0);
}
}

function Soldier::Right(%this, %pressed)
{
if ( %pressed )
{
%this.setLinearVelocityX(%this.hSpeed);
}
else
{
%this.setLinearVelocityX(0);
}
}

function Soldier::Enter(%this, %pressed)
{
if ( %pressed )
{
echo("Grenade!!!");
}
}


#1
08/11/2010 (4:13 am)
try adding this
function Soldier::onLevelEnded(%this)
{
   moveMap.unbind(keyboard, "w");
   moveMap.unbind(keyboard, "s");
   moveMap.unbind(keyboard, "a");
   moveMap.unbind(keyboard, "d");
   moveMap.unbind(keyboard, "enter"); 
}
hope that helps