private static void LoadAnimation(AnimationInfo animInfo) { var animation = new Animation {Texture = G.Content.Load<Texture2D>(animInfo.AssetName), Frames = new List<Frame>()}; foreach (var frameInfo in animInfo.Frames) { var sourceRect = GetIndexSourceRectangle(animation.Texture.Width, animation.Texture.Height, animInfo.Width, animInfo.Height, frameInfo.Index); var frame = new Frame(sourceRect, frameInfo.Duration); animation.Frames.Add(frame); } Animations.Add(animInfo.Name, animation); }
private void GenerateFrames(int frameWidth, int frameHeight, int numFrames, double[] durations) { int cols = Texture.Width / frameWidth; int rows = Texture.Height / frameHeight; Frames = new List<Frame>(); totalFrames = numFrames; for (int j = 0; j < rows; j++) { for (int i = 0; i < cols && j*cols + i < numFrames; i++) { Frame newFrame = new Frame(new Rectangle(i*frameWidth, j*frameHeight, frameWidth, frameHeight)); if (durations != null) newFrame.Duration = (int)(durations[j * cols + i] * 10); Frames.Add(newFrame); } } }