From 1a9c3f619dd6b62e708ecc0b85f400e3c4710983 Mon Sep 17 00:00:00 2001 From: "Eevee (Evelyn Woods)" Date: Thu, 10 Sep 2020 11:05:24 -0600 Subject: [PATCH] Fix trying to draw out of bounds --- js/renderer-canvas.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/renderer-canvas.js b/js/renderer-canvas.js index 4d5982f..bec7183 100644 --- a/js/renderer-canvas.js +++ b/js/renderer-canvas.js @@ -77,16 +77,16 @@ export class CanvasRenderer { let yf0 = Math.floor(y0); // Note that when the viewport is exactly aligned to the grid, we need to draw the cells // just outside of it, or we'll miss objects partway through crossing the border - if (xf0 === x0) { + if (xf0 === x0 && xf0 > 0) { xf0 -= 1; } - if (yf0 === y0) { + if (yf0 === y0 && yf0 > 0) { yf0 -= 1; } // Find where to stop drawing. As with above, if we're aligned to the grid, we need to // include the tiles just outside it, so we allow this fencepost problem to fly - let x1 = Math.ceil(x0 + this.viewport_size_x); - let y1 = Math.ceil(y0 + this.viewport_size_y); + let x1 = Math.min(this.level.size_x - 1, Math.ceil(x0 + this.viewport_size_x)); + let y1 = Math.min(this.level.size_y - 1, Math.ceil(y0 + this.viewport_size_y)); // Draw one layer at a time, so animated objects aren't overdrawn by // neighboring terrain // XXX layer count hardcoded here