Skip to content

Commit

Permalink
CanvasRenderer initial bg color draw on Game boot
Browse files Browse the repository at this point in the history
  • Loading branch information
pavle-goloskokovic committed Dec 24, 2024
1 parent 3e37888 commit c4871a0
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/renderer/canvas/CanvasRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var Events = require('../events');
var GetBlendModes = require('./utils/GetBlendModes');
var ScaleEvents = require('../../scale/events');
var TextureEvents = require('../../textures/events');
var GameEvents = require('../../core/events');
var TransformMatrix = require('../../gameobjects/components/TransformMatrix');

/**
Expand Down Expand Up @@ -54,7 +55,8 @@ var CanvasRenderer = new Class({
clearBeforeRender: gameConfig.clearBeforeRender,
backgroundColor: gameConfig.backgroundColor,
antialias: gameConfig.antialias,
roundPixels: gameConfig.roundPixels
roundPixels: gameConfig.roundPixels,
transparent: gameConfig.transparent
};

/**
Expand Down Expand Up @@ -113,8 +115,8 @@ var CanvasRenderer = new Class({
this.gameCanvas = game.canvas;

var contextOptions = {
alpha: game.config.transparent,
desynchronized: game.config.desynchronized,
alpha: gameConfig.transparent,
desynchronized: gameConfig.desynchronized,
willReadFrequently: false
};

Expand Down Expand Up @@ -143,7 +145,7 @@ var CanvasRenderer = new Class({
* @type {boolean}
* @since 3.20.0
*/
this.antialias = game.config.antialias;
this.antialias = gameConfig.antialias;

/**
* The blend modes supported by the Canvas Renderer.
Expand Down Expand Up @@ -226,7 +228,24 @@ var CanvasRenderer = new Class({
*/
init: function ()
{
this.game.textures.once(TextureEvents.READY, this.boot, this);
var game = this.game;

game.events.once(GameEvents.BOOT, function ()
{
var config = this.config;

if (!config.transparent)
{
var ctx = this.gameContext;
var gameCanvas = this.gameCanvas;

ctx.fillStyle = config.backgroundColor.rgba;
ctx.fillRect(0, 0, gameCanvas.width, gameCanvas.height);
}

}, this);

game.textures.once(TextureEvents.READY, this.boot, this);
},

/**
Expand Down Expand Up @@ -787,7 +806,7 @@ var CanvasRenderer = new Class({
gx = Math.floor(gx);
gy = Math.floor(gy);
}

spriteMatrix.applyITRS(gx, gy, sprite.rotation, sprite.scaleX * flipX, sprite.scaleY * flipY);

camMatrix.copyFrom(camera.matrix);
Expand Down

0 comments on commit c4871a0

Please sign in to comment.