Fix trying to draw out of bounds

This commit is contained in:
Eevee (Evelyn Woods) 2020-09-10 11:05:24 -06:00
parent 6b5b8b06aa
commit 1a9c3f619d

View File

@ -77,16 +77,16 @@ export class CanvasRenderer {
let yf0 = Math.floor(y0); let yf0 = Math.floor(y0);
// Note that when the viewport is exactly aligned to the grid, we need to draw the cells // 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 // just outside of it, or we'll miss objects partway through crossing the border
if (xf0 === x0) { if (xf0 === x0 && xf0 > 0) {
xf0 -= 1; xf0 -= 1;
} }
if (yf0 === y0) { if (yf0 === y0 && yf0 > 0) {
yf0 -= 1; yf0 -= 1;
} }
// Find where to stop drawing. As with above, if we're aligned to the grid, we need to // 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 // include the tiles just outside it, so we allow this fencepost problem to fly
let x1 = Math.ceil(x0 + this.viewport_size_x); let x1 = Math.min(this.level.size_x - 1, Math.ceil(x0 + this.viewport_size_x));
let y1 = Math.ceil(y0 + this.viewport_size_y); 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 // Draw one layer at a time, so animated objects aren't overdrawn by
// neighboring terrain // neighboring terrain
// XXX layer count hardcoded here // XXX layer count hardcoded here