Game Development Community

Moving one single sprite around - not fluent?

by Michael Kroeger · in Torque Developer Network · 04/02/2009 (10:47 am) · 0 replies

I made a small test-game with Torque Game Builder and one self created png image of the size 128x128 which has 4 cells. So each cell has a size of 64.
I want to move the first cell around by keyboard inputs and I used for this nearly the same code as in the tutorial:


function PlayerFlyer::onLevelLoaded(%this, %scenegraph)
{
   $PlayerFlyer=%this;
   
   moveMap.bindCmd(keyboard, "w", "PlayerFlyerUp();", "PlayerFlyerUpStop();");
   moveMap.bindCmd(keyboard, "s", "PlayerFlyerDown();", "PlayerFlyerDownStop();");
   moveMap.bindCmd(keyboard, "a", "PlayerFlyerLeft();", "PlayerFlyerLeftStop();");
   moveMap.bindCmd(keyboard, "d", "PlayerFlyerRight();", "PlayerFlyerRightStop();");

}

function PlayerFlyer::updateMovement(%this)
{
   if($PlayerFlyer.moveLeft)
   {
      $PlayerFlyer.setLinearVelocityX( -$PlayerFlyer.LeftSpeed );
   }
   
   if($PlayerFlyer.moveRight)
   {
      $PlayerFlyer.setLinearVelocityX( $PlayerFlyer.RightSpeed );
   }

   if($PlayerFlyer.moveUp)
   {
      $PlayerFlyer.setLinearVelocityY( -$PlayerFlyer.UpSpeed );
      $PlayerFlyer.setFrame(2);
   }


   if($PlayerFlyer.moveDown)
   {
      $PlayerFlyer.setLinearVelocityY( $PlayerFlyer.DownSpeed );
      $PlayerFlyer.setFrame(1);
   }


   if(!$PlayerFlyer.moveLeft && !$PlayerFlyer.moveRight)
   {
      $PlayerFlyer.setLinearVelocityX( 0 );
   }


   if(!$PlayerFlyer.moveUp && !$PlayerFlyer.moveDown)
   {
      $PlayerFlyer.setLinearVelocityY( 0 );
   }
}


function PlayerFlyerUp()
{
   $PlayerFlyer.moveUp = true;
   $PlayerFlyer.updateMovement();
}


function PlayerFlyerDown()
{
   $PlayerFlyer.moveDown = true;
   $PlayerFlyer.updateMovement();
}


function PlayerFlyerLeft()
{
   $PlayerFlyer.moveLeft = true;
   $PlayerFlyer.updateMovement();
}


function PlayerFlyerRight()
{
   $PlayerFlyer.moveRight = true;
   $PlayerFlyer.updateMovement();
}


function PlayerFlyerUpStop()
{
   $PlayerFlyer.moveUp = false;
   $PlayerFlyer.setFrame(0);   
   $PlayerFlyer.updateMovement();
}


function PlayerFlyerDownStop()
{
   $PlayerFlyer.moveDown = false;
   $PlayerFlyer.setFrame(0);   
   $PlayerFlyer.updateMovement();   
}

function PlayerFlyerLeftStop()
{
   $PlayerFlyer.moveLeft = false;
   $PlayerFlyer.updateMovement();
}


function PlayerFlyerRightStop()
{
   $PlayerFlyer.moveRight = false;
   $PlayerFlyer.updateMovement();
}

All of the speed variables have a value of 15.

In general it works as intended but the moving of the sprite isnt fluent. Often it seems as if the sprite jumps over some single pixle.
How can this be? It's only one sprite so the PC should be able to handle this. :)

About the author

Recent Threads