Listanimations = new List (); int frameWidth = 32; int frameHeight = 32; Animation idleAnimation = new Animation(); idleAnimation.AddFrame(new Rectangle(0, 0, frameWidth, frameHeight), TimeSpan.FromSeconds(1.0)); animations.Add(idleAnimation); Animation walkAnimation = new Animation(); walkAnimation.AddFrame(new Rectangle(frameWidth, 0, frameWidth, frameHeight), TimeSpan.FromSeconds(0.1)); walkAnimation.AddFrame(new Rectangle(frameWidth * 2, 0, frameWidth, frameHeight), TimeSpan.FromSeconds(0.1)); animations.Add(walkAnimation);
ListThis code creates a list of three animations for a more complex game. The texture for the player is loaded from a content manager (`content`). The first animation (`idleAnimation`) is similar to Example 1. The second animation (`walkingAnimation`) has eight frames and each frame lasts for 0.1 seconds. The third animation (`jumpingAnimation`) has four frames and each frame lasts for 0.1 seconds. This example also uses classes from the XNA Game Studio package library.animations = new List (); int frameWidth = 64; int frameHeight = 64; Texture2D playerTexture = content.Load ("player"); Animation idleAnimation = new Animation(); idleAnimation.AddFrame(new Rectangle(0, 0, frameWidth, frameHeight), TimeSpan.FromSeconds(1.0)); animations.Add(idleAnimation); Animation walkingAnimation = new Animation(); for (int i = 0; i < 8; i++) { walkingAnimation.AddFrame(new Rectangle(i * frameWidth, frameHeight * 1, frameWidth, frameHeight), TimeSpan.FromSeconds(0.1)); } animations.Add(walkingAnimation); Animation jumpingAnimation = new Animation(); for (int i = 0; i < 4; i++) { jumpingAnimation.AddFrame(new Rectangle(i * frameWidth, frameHeight * 2, frameWidth, frameHeight), TimeSpan.FromSeconds(0.1)); } animations.Add(jumpingAnimation);