Game Development Community

setAnimation function

by rennie moffat · in Torque Game Builder · 08/31/2009 (1:52 pm) · 7 replies

Hi there, I am using this setAnimation function to control my player's animation calls. He runs, when moving left right, but continues to run when I stop him.
function playerClass::setCurrentAnimation(%this)
{
   %xVelocity = %this.getLinearVelocityX();
   %yVelocity = %this.getLinearVelocityY();

   if (%xVelocity > 0)
   {
      %this.setFlip(false, false);
   }
   else if (%xVelocity < 0)
   {
      %this.setFlip(true, false);
   }
   
   if (%this.airborne)
   {
      if(%yVelocity < 0)
      {
         %this.playAnimation(PlayerJumpUpAnimation);
         return;
      }else
      {
         %this.playAnimation(PlayerJumpDownAnimation);
         return;
      }
   }

   if ($player.moveLeft == true || $player.moveRight == true)
   {
      if (%this.getAnimationName() $= "playerRunAnimation")
      {
         if(%this.getIsAnimationFinished())
         {
            %this.playAnimation(PlayerRunAnimation);
            return;
         }
      }else
      {
         %this.playAnimation(PlayerRunAnimation);
      }
   }else
   {
      %this.playAnimation(PlayerStandAnimation);
   }
}

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.


#1
09/01/2009 (1:07 pm)
I have looked and looked at this but cant yet decipher why certain animations are not being called. Specifically stand.


Any help would be great. Break it down for me fellas.
#2
09/01/2009 (3:58 pm)
i don't have an answer for you (at first glance, the code seems OK) but i have a process - check your console for errors, put echo statements at each "if" statement and before you set your animations, make sure they're OK (i use a toString(%object) method that prints the ID, name and class - if you have an error like misspelling the name, you'll get an error)

function playerClass::setCurrentAnimation(%this)
{
echo("playerClass::setCurrentAnimation(" @ %this.getID() @ ")");

   %xVelocity = %this.getLinearVelocityX();
   %yVelocity = %this.getLinearVelocityY();
echo(" current velocity x=[" @ %xVelocity @ "] y=[" @ %yVelocity @ "]");

   if (%xVelocity > 0)
   {
      %this.setFlip(false, false);
   }
   else if (%xVelocity < 0)
   {
      %this.setFlip(true, false);
   }
   
echo(" airborne=[" @ %this.airborne @ "]");
   if (%this.airborne)
   {
      if(%yVelocity < 0)
      {
echo(" setting animation to " @ PlayerJumpUpAnimation.getID() SPC
       PlayerJumpUpAnimation.getName());
         %this.playAnimation(PlayerJumpUpAnimation);
         return;
      }
...
#3
09/01/2009 (4:40 pm)
ok will do thanks. keep you posted. Have a lot on the go right now so hopefully get to it tonight.
#4
09/01/2009 (7:43 pm)
Cool, I just found it. I had scripted my player as ClassPlayer but named him as playerStandAnimation. Thats why there were glitches, none now.



I suppose this is because all multi animated objects, have many ani's, require only a class generally speaking, the Name confuses it.


Nice.

:]...k
#5
09/01/2009 (7:51 pm)
EDIT<
My bad perhaps the real is I just noticed I had a completely different animation name.

That would be more accurate. Correct?
#6
09/02/2010 (7:03 am)
Can any buddy give me the tutorial of a ball this is moving continoulsly .. in torque
#7
09/02/2010 (5:34 pm)
Giving an object a name does not cause problems. What causes problems is using the same name is different areas. You cannot give an object a name, say, "Bob", and have a class called "Bob", and an animation called "Bob", and so on. And you can't give multiple objects the name "Bob" and you can't give different types of objects the class "Bob".

Rules of thumb:
1) Any name you give must be 100% unique in your *whole* program.
2) Any class you give must be 100% unique to a type (static sprites/animated sprites/text objects/etc.).
3) All images/animations must have a name that is 100% unique in your *whole* program. This is really the same as (1), but it feels different when using TGB.

@Muhammed - You shouldn't add random comments to a thread. It is considered rude. Have you tried the tutorials that come with TGB? They are in the documentation that came with TGB.