setting animation to pull
by rennie moffat · in Torque Game Builder · 10/01/2009 (1:36 pm) · 0 replies
Hi guys,
perhaps you could help me with this. I am trying to get my player to animation on up and down, stop movements.
The code, to me, seems fine, does not crash my game. I pretty much followed easy to learn steps but nothing yet.
I have placed a %this.setCurrentAnimation in the onUpdate function, also tried it with a setCurrentAnimation call in the function playerUp, down etc.
Here is the full code.
perhaps you could help me with this. I am trying to get my player to animation on up and down, stop movements.
The code, to me, seems fine, does not crash my game. I pretty much followed easy to learn steps but nothing yet.
function playerClass::setCurrentAnimation(%this)
{
%yVelocity = $PlayerShip.getlinearVelocityY();
if (%yVelocity < 0)
{
$PlayerShip.playAnimation(playerShipUp_Animation);
return;
}
else if (%yVelocity > 0)
{
$PlayerShip.playAnimation(playerShipDown_Animation);
return;
}
else if (%yVelocity = 0)
{
$PlayerShip.playAnimation(playerShipFlat_Animation);
return;
}
}I have placed a %this.setCurrentAnimation in the onUpdate function, also tried it with a setCurrentAnimation call in the function playerUp, down etc.
Here is the full code.
function playerClass::onLevelLoaded(%this, %scenegraph)
{
$PlayerShip = %this;
moveMap.bindCmd(keyboard, "left", "playerLeft();", "playerLeftStop();");
moveMap.bindCmd(keyboard, "right", "playerRight();", "playerRightStop();");
moveMap.bindCmd(keyboard, "up", "playerUp();", "playerUpStop();");
moveMap.bindCmd(keyboard, "down", "playerDown();", "playerDownStop();");
%this.enableUpdateCallback();
}
function playerClass::onUpdate(%this)
{
%this.updateHorizontal();
%this.updateVertical();
%this.setCurrentAnimation();
}
function playerLeft()
{
$PlayerShip.moveLeft = true;
%this.UpdateHorizontal();
}
function playerLeftStop()
{
$PlayerShip.moveLeft = false;
$PlayerShip.UpdateHorizontal();
}
function playerRight()
{
$PlayerShip.moveRight = true;
$PlayerShip.UpdateHorizontal();
}
function playerRightStop()
{
$PlayerShip.moveRight = false;
$PlayerShip.UpdateHorizontal();
}
function playerUp()
{
$PlayerShip.moveUp = true;
$PlayerShip.UpdateVertical();
}
function playerUpStop()
{
$PlayerShip.moveUp = false;
$PlayerShip.UpdateVertical();
$PlayerShip.setCurrentAnimation();
}
function playerDown()
{
$PlayerShip.moveDown = true;
$PlayerShip.UpdateVertical();
$PlayerShip.setCurrentAnimation();
}
function playerDownStop()
{
$PlayerShip.moveDown = false;
$PlayerShip.UpdateVertical();
$PlayerShip.setCurrentAnimation();
}
function playerClass::updateHorizontal(%this)
{
if ($PlayerShip.moveLeft == $PlayerShip.moveRight)
{
$PlayerShip.setLinearVelocityX(20);
return;
}
else if ($PlayerShip.moveLeft)
{
$PlayerShip.setLinearVelocityX(-20);
return;
}
else if ($PlayerShip.moveRight)
{
$PlayerShip.setLinearVelocityX(40);
return;
}
}
function playerClass::updateVertical(%this)
{
if ($PlayerShip.moveUp == $PlayerShip.moveDown)
{
$PlayerShip.setLinearVelocityY(0);
return;
}
else if ($PlayerShip.moveUp)
{
$PlayerShip.setLinearVelocityY(-30);
return;
}
else if (%this.moveDown)
{
$PlayerShip.setLinearVelocityY(30);
return;
}
}
function playerClass::setCurrentAnimation(%this)
{
%yVelocity = $PlayerShip.getlinearVelocityY();
if (%yVelocity < 0)
{
$PlayerShip.playAnimation(playerShipUp_Animation);
return;
}
else if (%yVelocity > 0)
{
$PlayerShip.playAnimation(playerShipDown_Animation);
return;
}
else if (%yVelocity = 0)
{
$PlayerShip.playAnimation(playerShipFlat_Animation);
return;
}
}About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.