Creating an animated sprite from scratch
by Arden · in Torque Game Builder · 08/18/2010 (8:56 pm) · 2 replies
Hiya, I'm trying to create an animated sprite from code when a level is loaded and I can't figure out what I'm doing wrong. When I press the up key, it's not detected and I don't get the "up pressed" message.
Any help would be appreciated.
Thx!
echo ("STARTING SOLDIER.CS...!");
%soldier = new t2dAnimatedSprite()
{
scenegraph = %this.scenegraph;
config = "soldierDataBlock";
};
%this=%soldier
%soldier.setPosition(-38.643, 12.288);
echo ("Sprite created!");
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);
%gold = 0;
echo ("Keys bound!");
}
function Soldier::Up(%this, %pressed)
{
if ( %pressed )
{
echo ("Up key pressed!");
%this.setLinearVelocityY(-%this.vSpeed);
%this.setAnimation("Archer_walk_northAnimation");
}
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!!!");
}
}
Any help would be appreciated.
Thx!
echo ("STARTING SOLDIER.CS...!");
%soldier = new t2dAnimatedSprite()
{
scenegraph = %this.scenegraph;
config = "soldierDataBlock";
};
%this=%soldier
%soldier.setPosition(-38.643, 12.288);
echo ("Sprite created!");
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);
%gold = 0;
echo ("Keys bound!");
}
function Soldier::Up(%this, %pressed)
{
if ( %pressed )
{
echo ("Up key pressed!");
%this.setLinearVelocityY(-%this.vSpeed);
%this.setAnimation("Archer_walk_northAnimation");
}
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!!!");
}
}
Torque 3D Owner Ronny Bangsund
Torque Cheerleaders