public void UpdateAnimation(AnimatedObject animation, GameTime gameTime) { animation.wasActive = animation.Active; if (animation.Active) { animation.TimeSinceLastFrame += gameTime.ElapsedGameTime; if (animation.TimeSinceLastFrame >= TimeSpan.FromMilliseconds(animation.MillisecondsBetweenFrames)) { animation.CurrentFrame.X++; if (animation.CurrentFrame.X > animation.SheetFrameSize.X - 1) { animation.CurrentFrame.X = 0; animation.CurrentFrame.Y++; if (animation.CurrentFrame.Y > animation.SheetFrameSize.Y - 1) animation.CurrentFrame.Y = 0; } animation.FrameRect = new Rectangle(animation.CurrentFrame.X * animation.FrameSize.X, animation.CurrentFrame.Y * animation.FrameSize.Y, animation.FrameSize.X, animation.FrameSize.Y); animation.TimeSinceLastFrame = TimeSpan.Zero; } animation.UpdateTimer(gameTime); } }
public void DrawAnimatedObject(AnimatedObject component, GraphicObject parent) { if (component.Texture == null) { component.Texture = Game.Content.Load<Texture2D>("Interface/Assets/" + component.TextureLocation); component.FrameRect = new Rectangle(0, 0, component.FrameSize.X, component.FrameSize.Y); } component.Size.X = parent.Size.X / 100 * component.iSize.X; component.Size.Y = parent.Size.Y / 100 * component.iSize.Y; component.Position.X = parent.Size.X / 100 * component.iPosition.X - (component.Size.X / 2); component.Position.Y = parent.Size.Y / 100 * component.iPosition.Y - (component.Size.Y / 2); component.Position += parent.Position; SpriteManager.Draw(component.Texture, new Rectangle((int)component.Position.X, (int)component.Position.Y, (int)component.Size.X, (int)component.Size.Y), component.FrameRect, Color.White); }