From 1c473afa847b175d422e5f5af763b9345e38c056 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 17 Jul 2018 23:26:30 +0100 Subject: [PATCH] Cameras draw their backgrounds correctly at higher resolutions --- src/renderer/canvas/CanvasRenderer.js | 9 +++++++-- src/renderer/webgl/WebGLRenderer.js | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/renderer/canvas/CanvasRenderer.js b/src/renderer/canvas/CanvasRenderer.js index ad32c6c28..2e5289b1f 100644 --- a/src/renderer/canvas/CanvasRenderer.js +++ b/src/renderer/canvas/CanvasRenderer.js @@ -385,6 +385,11 @@ var CanvasRenderer = new Class({ var list = children.list; var resolution = this.config.resolution; + var cx = Math.floor(camera.x * resolution); + var cy = Math.floor(camera.y * resolution); + var cw = Math.floor(camera.width * resolution); + var ch = Math.floor(camera.height * resolution); + this.currentContext = ctx; // If the alpha or blend mode didn't change since the last render, then don't set them again (saves 2 ops) @@ -392,7 +397,7 @@ var CanvasRenderer = new Class({ if (!camera.transparent) { ctx.fillStyle = camera.backgroundColor.rgba; - ctx.fillRect(camera.x, camera.y, camera.width, camera.height); + ctx.fillRect(cx, cy, cw, ch); } ctx.globalAlpha = camera.alpha; @@ -413,7 +418,7 @@ var CanvasRenderer = new Class({ { ctx.save(); ctx.beginPath(); - ctx.rect(camera.x * resolution, camera.y * resolution, camera.width * resolution, camera.height * resolution); + ctx.rect(cx, cy, cw, ch); ctx.clip(); } diff --git a/src/renderer/webgl/WebGLRenderer.js b/src/renderer/webgl/WebGLRenderer.js index fbb2a73ce..8d7502978 100644 --- a/src/renderer/webgl/WebGLRenderer.js +++ b/src/renderer/webgl/WebGLRenderer.js @@ -1484,7 +1484,7 @@ var WebGLRenderer = new Class({ FlatTintPipeline.batchFillRect( 0, 0, 1, 1, 0, - camera.x, camera.y, camera.width, camera.height, + cx, cy, cw, ch, Utils.getTintFromFloats(color.redGL, color.greenGL, color.blueGL, 1.0), color.alphaGL, 1, 0, 0, 1, 0, 0,