From 0b3f9fdd9e860b9de30dc2162a1e94678449be45 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 24 Dec 2023 07:32:31 -0800 Subject: [PATCH] Adjust sprite hide bounds for aspect ratio --- src/render/gpustate.rs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/render/gpustate.rs b/src/render/gpustate.rs index 2b9b0cb..0748b6a 100644 --- a/src/render/gpustate.rs +++ b/src/render/gpustate.rs @@ -207,8 +207,8 @@ impl GPUState { // Game coordinates (relative to camera) of ne and sw corners of screen. // Used to skip off-screen sprites. - let clip_ne = Point2::from((-1.0, 1.0)) * game.camera.zoom; - let clip_sw = Point2::from((1.0, -1.0)) * game.camera.zoom; + let clip_ne = Point2::from((-self.window_aspect, 1.0)) * game.camera.zoom; + let clip_sw = Point2::from((self.window_aspect, -1.0)) * game.camera.zoom; for s in game.sprites() { // Parallax is computed here, so we can check if this sprite is visible. @@ -216,11 +216,7 @@ impl GPUState { let texture = self.texture_array.get_texture(&s.name[..]); // Game dimensions of this sprite post-scale. - // - // We only need height / 2 to check if we're on the screen, - // but we omit the division. - // This gives us a small margin, and lets us re-use the value - // without an extra multiply. + // Don't divide by 2, we use this later. let height = s.height * s.scale; let width = height * texture.aspect; @@ -234,13 +230,6 @@ impl GPUState { continue; } - // Compute the values we need to draw - // scale: combines texture scale and zoom scale. - // screen_pos: position of this sprite in screen coordinates - // - // We can't use screen_pos to exclude off-screen sprites because - // it can't account for height and width. - instances.push(SpriteInstance { position: pos.into(), aspect: texture.aspect,