/// <summary> /// Makes a new animated object. /// </summary> /// <param name="world"></param> /// <param name="position"></param> /// <param name="velocity"></param> /// <param name="size"></param> /// <param name="animations">All the animations of the object.</param> /// <param name="startAnimation">The name of the first animation to play of this object.</param> /// <param name="gravitable"></param> public GameObject(World world, Vector2 position, Vector2 velocity, Vector2 size, List<AnimationSet> animations, String startAnimation, bool gravitable, bool collidesWithTerrain, int health) { this.world = world; this.Position = position; this.Velocity = velocity; this.Size = size; this.gravitable = gravitable; this.Animations = animations; this.CurAnimation = GetAnimationByName(startAnimation); this.CollidesWithTerrain = collidesWithTerrain; this.Health = health; }
/// <summary> /// Changes the animation being played. Doesn't do anything if called with the name of the currently /// playing animation. /// </summary> /// <param name="name">The name of the new animation.</param> /// <exception cref="System.InvalidOperationException">Specified animation doesn't exist.</exception> protected virtual void ChangeAnimation(string name) { if (!CurAnimation.IsCalled(name)) { AnimationSet newAnimation = GetAnimationByName(name); if (newAnimation == null) throw new InvalidOperationException("Specified animation doesn't exist."); newAnimation.Reset(); newAnimation.Update(); CurAnimation = newAnimation; } }