Example #1
0
        private void UpdateAnimation()
        {
            // if they are currently moving
            if (Math.Abs(Velocity.X) > 0 || Math.Abs(Velocity.Y) > 0)
            {
                // find out what directions they are actually moving...
                var actualDir = ParseActualDirection(Velocity.X, Velocity.Y);
                // ... and what direction the animation is facing
                var currentDir = StringToDirection(Sprite.GetAnimation().Split(' ')[1]);

                Direction = actualDir[0];

                // if they aren't facing a valid direction, correct it
                if (!actualDir.Contains(currentDir))
                {
                    Sprite.SetAnimation(String.Format("walking {0}", actualDir[0].ToString().ToLower()));
                }

                // if the animation is standing, change it to moving
                if (Sprite.GetAnimation().Split(' ')[0] == "standing")
                {
                    Sprite.SetAnimation(Sprite.GetAnimation().Replace("standing", "walking"));
                }
            }
            else
            {
                // make sure they are standing if they have no velocity
                Sprite.SetAnimation("standing " + Direction.ToString().ToLower());
            }
        }