Skip to content

Commit 217e273

Browse files
committed
Added context save to stop fillRect bug (issue phaserjs#4056)
1 parent 7bfd213 commit 217e273

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

src/renderer/canvas/CanvasRenderer.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ var CanvasRenderer = new Class({
373373
var width = this.width;
374374
var height = this.height;
375375

376+
ctx.globalAlpha = 1;
377+
ctx.globalCompositeOperation = 'source-over';
378+
ctx.setTransform(1, 0, 0, 1, 0, 0);
379+
376380
if (config.clearBeforeRender)
377381
{
378382
ctx.clearRect(0, 0, width, height);
@@ -384,6 +388,8 @@ var CanvasRenderer = new Class({
384388
ctx.fillRect(0, 0, width, height);
385389
}
386390

391+
ctx.save();
392+
387393
this.drawCount = 0;
388394
},
389395

@@ -414,8 +420,6 @@ var CanvasRenderer = new Class({
414420

415421
this.currentContext = ctx;
416422

417-
// If the alpha or blend mode didn't change since the last render, then don't set them again (saves 2 ops)
418-
419423
if (!camera.transparent)
420424
{
421425
ctx.fillStyle = camera.backgroundColor.rgba;
@@ -428,9 +432,10 @@ var CanvasRenderer = new Class({
428432

429433
this.drawCount += list.length;
430434

435+
ctx.save();
436+
431437
if (scissor)
432438
{
433-
ctx.save();
434439
ctx.beginPath();
435440
ctx.rect(cx, cy, cw, ch);
436441
ctx.clip();
@@ -474,11 +479,7 @@ var CanvasRenderer = new Class({
474479

475480
camera.dirty = false;
476481

477-
// Reset the camera scissor
478-
if (scissor)
479-
{
480-
ctx.restore();
481-
}
482+
ctx.restore();
482483

483484
if (camera.renderToTexture)
484485
{
@@ -500,8 +501,7 @@ var CanvasRenderer = new Class({
500501
{
501502
var ctx = this.gameContext;
502503

503-
ctx.globalAlpha = 1;
504-
ctx.globalCompositeOperation = 'source-over';
504+
ctx.restore();
505505

506506
if (this.snapshotCallback)
507507
{

0 commit comments

Comments
 (0)