Game Development Community

Setting/Playing other Animations

by Matt Huston · in Torque X 2D · 03/05/2007 (3:24 am) · 1 replies

I have a animation in my TGBX scene named player_Idle.

Somewhat similar to the TGBX Starter game, I would like to change the animation when the player is moving. In TGB I would have written something similar to %this.playAnimation(player_Run);

Anyway to do this in TGBX/TX?

#1
03/05/2007 (10:04 pm)
I load the animations at the beginning of the game ...

PlayerNorth = (T2DAnimatedSprite)(TorqueObjectDatabase.Instance.FindObject("playerNorth") as T2DAnimatedSprite).Clone();
            TorqueObjectDatabase.Instance.Register(_playerNorth);
            PlayerSouth = (T2DAnimatedSprite)(TorqueObjectDatabase.Instance.FindObject("playerSouth") as T2DAnimatedSprite).Clone();
            TorqueObjectDatabase.Instance.Register(_playerSouth);
            PlayerEast = (T2DAnimatedSprite)(TorqueObjectDatabase.Instance.FindObject("playerEast") as T2DAnimatedSprite).Clone();
            TorqueObjectDatabase.Instance.Register(_playerEast);
            PlayerWest = (T2DAnimatedSprite)(TorqueObjectDatabase.Instance.FindObject("playerWest") as T2DAnimatedSprite).Clone();
            TorqueObjectDatabase.Instance.Register(_playerWest);

then I switch them when the player turns ...

if (move.Sticks[0].X < 0)
                        {
                            (_player as T2DAnimatedSprite).Material = PlayerWest.Material;
                        }
                        else if (move.Sticks[0].X > 0)
                        {
                            (_player as T2DAnimatedSprite).Material = PlayerEast.Material;
                        }
                        else if (move.Sticks[0].Y > 0)
                        {
                            (_player as T2DAnimatedSprite).Material = PlayerNorth.Material;
                        }
                        else if (move.Sticks[0].Y < 0)
                        {
                            (_player as T2DAnimatedSprite).Material = PlayerSouth.Material;
                        }