Having trouble getting a sprite to do what I say
by sgtpieman · in Torque 2D Beginner · 02/14/2014 (7:57 pm) · 3 replies
So what I'm trying to do is make a platformer with two different sprites: the legs and the body.
The legs I have working like a charm. They move left, move right, jump, and fall. The problem is in the body. For some reason I can't get it to do anything. I mounted it on the legs already and that sorta works, but it doesn't mirror like the legs do and when I press the up key it doesn't display the sprite I want. Instead it is stuck on its default sprite and direction.
Does anyone know what I'm doing wrong? Here is the code if you need it. I tried to keep it super simple since all I need it to do is mirror depending on its direction it's moving and display an animation when I press up.
function torsoClass::onLevelLoaded(%this, %scenegraph)
{
$ptorso = %this;
moveMap.bindCmd(keyboard, "up", "torsofaceup();", "torsofacefront();");
}
function torsofaceup()
{
$playertorso.up = true;
}
function torsofacefront()
{
$playertorso.up = false;
}
//functions for keystrokes done
function torsoClass::setCurrentAnimation(%this)
{
%xVelocity = %this.getLinearVelocityX();
if (%xVelocity > 0)
{
%this.setFlip(false, false);
}
else if (%xVelocity < 0)
{
%this.setFlip(true, false);
}
//direction done
if ($playertorso.up = true)
{
%this.playAnimation(torsoup);
}
else
{
%this.playAnimation(torsorelaxedfront);
}
}
The legs I have working like a charm. They move left, move right, jump, and fall. The problem is in the body. For some reason I can't get it to do anything. I mounted it on the legs already and that sorta works, but it doesn't mirror like the legs do and when I press the up key it doesn't display the sprite I want. Instead it is stuck on its default sprite and direction.
Does anyone know what I'm doing wrong? Here is the code if you need it. I tried to keep it super simple since all I need it to do is mirror depending on its direction it's moving and display an animation when I press up.
function torsoClass::onLevelLoaded(%this, %scenegraph)
{
$ptorso = %this;
moveMap.bindCmd(keyboard, "up", "torsofaceup();", "torsofacefront();");
}
function torsofaceup()
{
$playertorso.up = true;
}
function torsofacefront()
{
$playertorso.up = false;
}
//functions for keystrokes done
function torsoClass::setCurrentAnimation(%this)
{
%xVelocity = %this.getLinearVelocityX();
if (%xVelocity > 0)
{
%this.setFlip(false, false);
}
else if (%xVelocity < 0)
{
%this.setFlip(true, false);
}
//direction done
if ($playertorso.up = true)
{
%this.playAnimation(torsoup);
}
else
{
%this.playAnimation(torsorelaxedfront);
}
}
#2
02/14/2014 (11:08 pm)
There's a difference? Boy do I feel like a fool. Okay, I'm switching to 2.0 now. I was on 1.7.6 before. That explains a lot. I'm sorry for wasting your time.
#3
In any case, if you do want to use the latest version, be sure to check out the Torque 2D wiki to get a better understanding of what has changed.
02/14/2014 (11:30 pm)
Don't worry, both engines share the same name but there are big differences in the source code. It's easy to mix things up. Plus with 2.0 (and the upcoming 3.0 release) you have to give up having editors, which is a big drawback for some users.In any case, if you do want to use the latest version, be sure to check out the Torque 2D wiki to get a better understanding of what has changed.
Associate Mike Lilligreen
Retired T2Der
Since this forum is for the open source version, my answers are tailored for that. First off, onLevelLoaded no longer exists as a callback. Also, I do not see anywhere in the code you provided a call to setCurrentAnimation, which could explain why the torso animation never updates.