Skip to content

Commit 1c473af

Browse files
committed
Cameras draw their backgrounds correctly at higher resolutions
1 parent e296712 commit 1c473af

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/renderer/canvas/CanvasRenderer.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,19 @@ var CanvasRenderer = new Class({
385385
var list = children.list;
386386
var resolution = this.config.resolution;
387387

388+
var cx = Math.floor(camera.x * resolution);
389+
var cy = Math.floor(camera.y * resolution);
390+
var cw = Math.floor(camera.width * resolution);
391+
var ch = Math.floor(camera.height * resolution);
392+
388393
this.currentContext = ctx;
389394

390395
// If the alpha or blend mode didn't change since the last render, then don't set them again (saves 2 ops)
391396

392397
if (!camera.transparent)
393398
{
394399
ctx.fillStyle = camera.backgroundColor.rgba;
395-
ctx.fillRect(camera.x, camera.y, camera.width, camera.height);
400+
ctx.fillRect(cx, cy, cw, ch);
396401
}
397402

398403
ctx.globalAlpha = camera.alpha;
@@ -413,7 +418,7 @@ var CanvasRenderer = new Class({
413418
{
414419
ctx.save();
415420
ctx.beginPath();
416-
ctx.rect(camera.x * resolution, camera.y * resolution, camera.width * resolution, camera.height * resolution);
421+
ctx.rect(cx, cy, cw, ch);
417422
ctx.clip();
418423
}
419424

src/renderer/webgl/WebGLRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ var WebGLRenderer = new Class({
14841484

14851485
FlatTintPipeline.batchFillRect(
14861486
0, 0, 1, 1, 0,
1487-
camera.x, camera.y, camera.width, camera.height,
1487+
cx, cy, cw, ch,
14881488
Utils.getTintFromFloats(color.redGL, color.greenGL, color.blueGL, 1.0),
14891489
color.alphaGL,
14901490
1, 0, 0, 1, 0, 0,

0 commit comments

Comments
 (0)