Game Development Community

4 way movement animation problem

by Spence890 · in Torque Game Builder · 10/14/2013 (7:24 pm) · 0 replies

I followed the mini platformer tutorial for my code I got rid of the animation flip and added movement for the other 3 directions. The movement works fine but as soon as I add the animation code for more then one direction none of the animations work except for the last one in the code and it only plays the first frame of the animation. Can someone please help me I'm new and I've tried everything I can't get it to work.

function playerClass::onLevelLoaded(%this, %scenegraph)  
    {  
       $Warrior = %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();");  
    }  
      
    function playerLeft()  
    {  
       $Warrior.moveLeft = true;  
    }  
      
    function playerLeftStop()  
    {  
       $Warrior.moveLeft = false;  
    }  
      
    function playerRight()  
    {  
       $Warrior.moveRight = true;  
    }  
      
    function playerRightStop()  
    {  
       $Warrior.moveRight = false;  
    }  
      
    function playerUp()  
    {  
       $Warrior.moveUp = true;  
    }  
      
    function playerUpStop()  
    {  
       $Warrior.moveUp = fase;  
    }  
      
    function playerDown()  
    {  
       $Warrior.moveDown = true;  
    }  
      
    function playerDownStop()  
    {  
       $Warrior.moveDown = false;  
    }  
      
    function playerClass::updateMovement(%this)  
    {  
       $Warrior.setCurrentAnimation();  
         
       if(%this.moveLeft)  
       {  
          %this.setLinearVelocityX(-60);  
       }  
         
       if(%this.moveRight)  
       {  
          %this.setLinearVelocityX(60);  
       }  
         
       if(%this.moveUp)  
       {  
          %this.setLinearVelocityY(-60);  
       }  
         
       if(%this.moveDown)  
       {  
          %this.setLinearVelocityY(60);  
       }  
         
       if(!%this.moveLeft && !%this.moveRight)  
       {  
          %this.setLinearVelocityX(0);  
       }  
         
       if(!%this.moveUp && !%this.moveDown)  
       {  
          %this.setLinearVelocityY(0);  
       }  
    }  
      
    function playerClass::setCurrentAnimation(%this)    
    {    
       if(%this.moveLeft)    
       {    
          if(%this.getAnimationName() $= "playerRunLeft")    
          {    
             if(%this.getIsAnimationFinished())    
             {    
                %this.playAnimation(playerRunLeft);    
             }    
          }    
          else    
          {    
             %this.playAnimation(playerRunLeft);    
          }    
       }    
       else    
       {    
          %this.playAnimation(playerStandLeft);    
       }    
            
       if(%this.moveRight)    
       {    
          if(%this.getAnimationName() $= "playerRunRight")    
          {    
             if(%this.getIsAnimationFinished())    
             {    
                %this.playAnimation(playerRunRight);    
             }    
          }    
          else    
          {    
             %this.playAnimation(playerRunRight);    
          }    
       }    
       else    
       {    
          %this.playAnimation(playerStandRight);    
       }    
            
       if(%this.moveUp)    
       {    
          if(%this.getAnimationName() $= "playerRunUp")    
          {    
             if(%this.getIsAnimationFinished())    
             {    
                %this.playAnimation(playerRunUp);    
             }    
          }    
          else    
          {    
             %this.playAnimation(playerRunUp);    
          }    
       }    
       else    
       {    
          %this.playAnimation(playerStandUp);    
       }    
            
       if(%this.moveDown)    
       {    
          if(%this.getAnimationName() $= "playerRunDown")    
          {    
             if(%this.getIsAnimationFinished())    
             {    
                %this.playAnimation(playerRunDown);    
             }    
          }    
          else    
          {    
             %this.playAnimation(playerRunDown);    
          }    
       }    
       else    
       {    
          %this.playAnimation(playerStandDown);    
       }    
    }    
      
    function t2dSceneGraph::onUpdateScene()  
    {  
       $Warrior.updateMovement();  
    }

Never mind I was able to figure it out, I removed a lot of the code. This makes more sense to me.

function playerClass::onLevelLoaded(%this, %scenegraph)
{
   $Warrior = %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();");
}

function playerLeft()
{
   $Warrior.moveLeft = true;
   $Warrior.playAnimation(playerRunLeft);
}

function playerLeftStop()
{
   $Warrior.moveLeft = false;
   $Warrior.playAnimation(playerStandLeft);
}

function playerRight()
{
   $Warrior.moveRight = true;
   $Warrior.playAnimation(playerRunRight);
}

function playerRightStop()
{
   $Warrior.moveRight = false;
   $Warrior.playAnimation(playerStandRight);
}

function playerUp()
{
   $Warrior.moveUp = true;
   $Warrior.playAnimation(playerRunUp);
}

function playerUpStop()
{
   $Warrior.moveUp = false;
   $Warrior.playAnimation(playerStandUp);
}

function playerDown()
{
   $Warrior.moveDown = true;
   $Warrior.playAnimation(playerRunDown);
}

function playerDownStop()
{
   $Warrior.moveDown = false;
   $Warrior.playAnimation(playerStandDown);
}

function playerClass::updateMovement(%this)
{
   if(%this.moveLeft)
   {
      %this.setLinearVelocityX(-60);
   }
   
   if(%this.moveRight)
   {
      %this.setLinearVelocityX(60);
   }
   
   if(%this.moveUp)
   {
      %this.setLinearVelocityY(-60);
   }
   
   if(%this.moveDown)
   {
      %this.setLinearVelocityY(60);
   }
   
   if(!%this.moveLeft && !%this.moveRight)
   {
      %this.setLinearVelocityX(0);
   }
   
   if(!%this.moveUp && !%this.moveDown)
   {
      %this.setLinearVelocityY(0);
   }
}

function t2dSceneGraph::onUpdateScene()
{
   $Warrior.updateMovement();
}