public static void Render <TSurface, TSource>(DirectGraphicsContext <TSurface, TSource> layer, CameraView view, ScreenRenderer <TSurface, TSource> r, List <Sprite> sprites, Transform transform = null) { IGameController controller = Woofer.Controller; foreach (Sprite sprite in sprites) { if (sprite.Source.X < 0 || sprite.Source.Y < 0) { continue; } float x = (float)sprite.Destination.X; float y = (float)sprite.Destination.Y; if (transform != null) { x += ((float)(transform.Position.X)); y += ((float)(transform.Position.Y)); } float width = (float)sprite.Destination.Width; float height = (float)sprite.Destination.Height; if (!new System.Drawing.RectangleF(x, y, width, height) .IntersectsWith( new System.Drawing.RectangleF((float)(view.X - layer.GetSize().Width / 2), (float)(view.Y - layer.GetSize().Height / 2), layer.GetSize().Width, layer.GetSize().Height))) { continue; } x -= (int)Math.Floor(view.X); y -= (int)Math.Floor(view.Y); y *= -1; y -= height; x += layer.GetSize().Width / 2; y += layer.GetSize().Height / 2; System.Drawing.Rectangle drawingRect = new System.Drawing.Rectangle((int)Math.Floor(x), (int)Math.Floor(y), (int)width, (int)height); layer.Draw(r.SpriteManager[sprite.Texture], drawingRect, sprite.Source != Rectangle.Empty ? sprite.Source.ToDrawing() : (System.Drawing.Rectangle?)null, new DrawInfo() { Mode = sprite.DrawMode, Color = System.Drawing.Color.FromArgb((int)(sprite.Opacity * 255), 255, 255, 255) }); } }
public void Render <TSurface, TSource>(DirectGraphicsContext <TSurface, TSource> layer, CameraView view, ScreenRenderer <TSurface, TSource> r) { IGameController controller = Woofer.Controller; Spatial spatial = Owner.Components.Get <Spatial>(); foreach (Sprite sprite in Sprites) { float x = (float)sprite.Destination.X; float y = (float)sprite.Destination.Y; if (spatial != null) { x += ((float)(spatial.X)); y += ((float)(spatial.Y)); } float width = (float)sprite.Destination.Width; float height = (float)sprite.Destination.Height; x -= (int)Math.Floor(controller.ActiveScene.CurrentViewport.X); y -= (int)Math.Floor(controller.ActiveScene.CurrentViewport.Y); y *= -1; y -= height; x += layer.GetSize().Width / 2; y += layer.GetSize().Height / 2; System.Drawing.Rectangle drawingRect = new System.Drawing.Rectangle((int)Math.Floor(x), (int)Math.Floor(y), (int)width, (int)height); if (sprite.Source is Rectangle source) { layer.Draw(r.SpriteManager[sprite.Texture], drawingRect, sprite.Source.ToDrawing()); } else { layer.Draw(r.SpriteManager[sprite.Texture], drawingRect); } } }