Animation data is null
by Brandon · in Torque X 2D · 01/17/2009 (9:29 am) · 5 replies
I'm trying to change some book code to animate my guy based on his rotation. For whatever reason my _anim* variables are all null as if they are not being set before the process tick is called.
I put default values for them, and they are set in the TXB as well. Not sure what I have to do.
My code is like this:
[TorqueXmlSchemaType(DefaultValue = "orc_forward_northAnimation")]
public T2DAnimationData AnimNorth
{
get { return _animNorth; }
set { _animNorth = value; }
}
SceneObject.Rotation += (move.Sticks[0].X * TurnSpeed);
if (SceneObject.Rotation >= 0 && SceneObject.Rotation < 45)
{
PlayMyAnimation(_animNorth);
}
_animNorth is always null
I put default values for them, and they are set in the TXB as well. Not sure what I have to do.
My code is like this:
[TorqueXmlSchemaType(DefaultValue = "orc_forward_northAnimation")]
public T2DAnimationData AnimNorth
{
get { return _animNorth; }
set { _animNorth = value; }
}
SceneObject.Rotation += (move.Sticks[0].X * TurnSpeed);
if (SceneObject.Rotation >= 0 && SceneObject.Rotation < 45)
{
PlayMyAnimation(_animNorth);
}
_animNorth is always null
#2
01/17/2009 (9:57 am)
Anyone know a good way to animate based on rotation? The way I'm trying is not working out too well.
#3
Do you want full 360 degree rotation or something more old school like eight directions?
01/17/2009 (5:52 pm)
Quote:Anyone know a good way to animate based on rotation?
Do you want full 360 degree rotation or something more old school like eight directions?
#4
I probably don't really need to change the rotation though. Maybe I can just change the "direction" that the sprite is considered to be facing and change the animation based on that.
I figured it would look OK if say for example he's facing between 90 and 135 degrees I can just use my east animation and once it gets to 135 use my south east animation.
01/17/2009 (8:07 pm)
Well my enemy character only has 8 directional animations, but when he shoots at me or runs to me he comes straight at me. So I was thinking maybe based on his rotation is how I could show the animation.I probably don't really need to change the rotation though. Maybe I can just change the "direction" that the sprite is considered to be facing and change the animation based on that.
I figured it would look OK if say for example he's facing between 90 and 135 degrees I can just use my east animation and once it gets to 135 use my south east animation.
#5
I implemented a similar directional system for character aiming. It's a side-scroller like Contra that allows for 8 directions of aiming. I created an enumeration for all my directions (East, SouthEast, South, etc.) and stored the current direction in a variable. Then I tested the input angle from the right stick on the gamepad with:
Once I had the angle I ran it through an if...else block like you are talking about to compare the angle with ranges of values. Based on the result I update the current direction and use the newly updated current direction to run animations accordingly.
01/17/2009 (9:28 pm)
I'm assuming your perspective is some form of top-down/isometric. In that case I think you would want to change the enemy's rotation so they would move in the proper direction. Think about how movement works in the Space Warrior tutorial - the stick sets the rotation and the move button accelerates you along that vector.I implemented a similar directional system for character aiming. It's a side-scroller like Contra that allows for 8 directions of aiming. I created an enumeration for all my directions (East, SouthEast, South, etc.) and stored the current direction in a variable. Then I tested the input angle from the right stick on the gamepad with:
_angle = T2DVectorUtil.AngleFromInput(new Vector2(move.Sticks[1].X, move.Sticks[1].Y));
Once I had the angle I ran it through an if...else block like you are talking about to compare the angle with ranges of values. Based on the result I update the current direction and use the newly updated current direction to run animations accordingly.
Torque Owner Brandon
cod3r on irc