Skip to content

Commit d7e7fee

Browse files
committed
Dimensions are now set in the onResize handlers.
1 parent c34648b commit d7e7fee

3 files changed

Lines changed: 68 additions & 45 deletions

File tree

src/renderer/canvas/CanvasRenderer.js

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,14 @@ var CanvasRenderer = new Class({
5858
*/
5959
this.drawCount = 0;
6060

61-
/**
62-
* The core Scale Manager.
63-
*
64-
* @name Phaser.Renderer.Canvas.CanvasRenderer#scaleManager
65-
* @type {Phaser.DOM.ScaleManager}
66-
* @since 3.16.0
67-
*/
68-
this.scaleManager = game.scale;
69-
7061
/**
7162
* The width of the canvas being rendered to.
7263
*
7364
* @name Phaser.Renderer.Canvas.CanvasRenderer#width
7465
* @type {integer}
7566
* @since 3.0.0
7667
*/
77-
this.width = this.scaleManager.baseSize.width;
68+
this.width = 0;
7869

7970
/**
8071
* The height of the canvas being rendered to.
@@ -83,7 +74,7 @@ var CanvasRenderer = new Class({
8374
* @type {integer}
8475
* @since 3.0.0
8576
*/
86-
this.height = this.scaleManager.baseSize.height;
77+
this.height = 0;
8778

8879
/**
8980
* The local configuration settings of the CanvasRenderer.
@@ -241,7 +232,31 @@ var CanvasRenderer = new Class({
241232
*/
242233
init: function ()
243234
{
244-
this.resize();
235+
this.game.scale.on('resize', this.onResize, this);
236+
237+
var baseSize = this.game.scale.baseSize;
238+
239+
this.resize(baseSize.width, baseSize.height);
240+
},
241+
242+
/**
243+
* The event handler that manages the `resize` event dispatched by the Scale Manager.
244+
*
245+
* @method Phaser.Renderer.Canvas.CanvasRenderer#onResize
246+
* @since 3.16.0
247+
*
248+
* @param {Phaser.Structs.Size} gameSize - The default Game Size object. This is the un-modified game dimensions.
249+
* @param {Phaser.Structs.Size} baseSize - The base Size object. The game dimensions multiplied by the resolution. The canvas width / height values match this.
250+
* @param {Phaser.Structs.Size} displaySize - The display Size object. The size of the canvas style width / height attributes.
251+
* @param {number} [resolution] - The Scale Manager resolution setting.
252+
*/
253+
onResize: function (gameSize, baseSize)
254+
{
255+
// Has the underlying canvas size changed?
256+
if (baseSize.width !== this.width || baseSize.height !== this.height)
257+
{
258+
this.resize(baseSize.width, baseSize.height);
259+
}
245260
},
246261

247262
/**
@@ -250,16 +265,11 @@ var CanvasRenderer = new Class({
250265
* @method Phaser.Renderer.Canvas.CanvasRenderer#resize
251266
* @since 3.0.0
252267
*
253-
* @param {number} [width] - The new width of the renderer. If not specified it uses the base size from the Scale Manager.
254-
* @param {number} [height] - The new height of the renderer. If not specified it uses the base size from the Scale Manager.
255-
* @param {number} [resolution] - The new resolution of the renderer. If not specified it uses the resolution from the Scale Manager.
268+
* @param {number} [width] - The new width of the renderer.
269+
* @param {number} [height] - The new height of the renderer.
256270
*/
257-
resize: function (width, height, resolution)
271+
resize: function (width, height)
258272
{
259-
if (width === undefined) { width = this.scaleManager.baseSize.width; }
260-
if (height === undefined) { height = this.scaleManager.baseSize.height; }
261-
if (resolution === undefined) { resolution = this.scaleManager.resolution; }
262-
263273
this.width = width;
264274
this.height = height;
265275

src/renderer/webgl/WebGLPipeline.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ var WebGLPipeline = new Class({
8787
* @type {number}
8888
* @since 3.0.0
8989
*/
90-
this.resolution = config.game.config.resolution;
90+
this.resolution = 1;
9191

9292
/**
9393
* Width of the current viewport
@@ -96,7 +96,7 @@ var WebGLPipeline = new Class({
9696
* @type {number}
9797
* @since 3.0.0
9898
*/
99-
this.width = config.game.config.width * this.resolution;
99+
this.width = 0;
100100

101101
/**
102102
* Height of the current viewport
@@ -105,7 +105,7 @@ var WebGLPipeline = new Class({
105105
* @type {number}
106106
* @since 3.0.0
107107
*/
108-
this.height = config.game.config.height * this.resolution;
108+
this.height = 0;
109109

110110
/**
111111
* The WebGL context this WebGL Pipeline uses.
@@ -305,10 +305,9 @@ var WebGLPipeline = new Class({
305305
*/
306306
resize: function (width, height, resolution)
307307
{
308-
this.resolution = resolution;
309-
310308
this.width = width * resolution;
311309
this.height = height * resolution;
310+
this.resolution = resolution;
312311

313312
return this;
314313
},

src/renderer/webgl/WebGLRenderer.js

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,32 +109,25 @@ var WebGLRenderer = new Class({
109109
*/
110110
this.type = CONST.WEBGL;
111111

112-
/**
113-
* The core Scale Manager.
114-
*
115-
* @name Phaser.Renderer.WebGL.WebGLRenderer#scaleManager
116-
* @type {Phaser.DOM.ScaleManager}
117-
* @since 3.16.0
118-
*/
119-
this.scaleManager = game.scale;
120-
121112
/**
122113
* The width of the canvas being rendered to.
114+
* This is populated in the onResize event handler.
123115
*
124116
* @name Phaser.Renderer.WebGL.WebGLRenderer#width
125117
* @type {integer}
126118
* @since 3.0.0
127119
*/
128-
this.width = this.scaleManager.baseSize.width;
120+
this.width = 0;
129121

130122
/**
131123
* The height of the canvas being rendered to.
124+
* This is populated in the onResize event handler.
132125
*
133126
* @name Phaser.Renderer.WebGL.WebGLRenderer#height
134127
* @type {integer}
135128
* @since 3.0.0
136129
*/
137-
this.height = this.scaleManager.baseSize.height;
130+
this.height = 0;
138131

139132
/**
140133
* The canvas which this WebGL Renderer draws to.
@@ -587,8 +580,6 @@ var WebGLRenderer = new Class({
587580

588581
this.setBlendMode(CONST.BlendModes.NORMAL);
589582

590-
this.resize();
591-
592583
this.game.events.once('texturesready', this.boot, this);
593584

594585
return this;
@@ -621,6 +612,32 @@ var WebGLRenderer = new Class({
621612
gl.enable(gl.SCISSOR_TEST);
622613

623614
this.setPipeline(this.pipelines.TextureTintPipeline);
615+
616+
this.game.scale.on('resize', this.onResize, this);
617+
618+
var baseSize = this.game.scale.baseSize;
619+
620+
this.resize(baseSize.width, baseSize.height, this.game.scale.resolution);
621+
},
622+
623+
/**
624+
* The event handler that manages the `resize` event dispatched by the Scale Manager.
625+
*
626+
* @method Phaser.Renderer.WebGL.WebGLRenderer#onResize
627+
* @since 3.16.0
628+
*
629+
* @param {Phaser.Structs.Size} gameSize - The default Game Size object. This is the un-modified game dimensions.
630+
* @param {Phaser.Structs.Size} baseSize - The base Size object. The game dimensions multiplied by the resolution. The canvas width / height values match this.
631+
* @param {Phaser.Structs.Size} displaySize - The display Size object. The size of the canvas style width / height attributes.
632+
* @param {number} [resolution] - The Scale Manager resolution setting.
633+
*/
634+
onResize: function (gameSize, baseSize, displaySize, resolution)
635+
{
636+
// Has the underlying canvas size changed?
637+
if (baseSize.width !== this.width || baseSize.height !== this.height || resolution !== this.resolution)
638+
{
639+
this.resize(baseSize.width, baseSize.height, resolution);
640+
}
624641
},
625642

626643
/**
@@ -629,23 +646,20 @@ var WebGLRenderer = new Class({
629646
* @method Phaser.Renderer.WebGL.WebGLRenderer#resize
630647
* @since 3.0.0
631648
*
632-
* @param {number} [width] - The new width of the renderer. If not specified it uses the base size from the Scale Manager.
633-
* @param {number} [height] - The new height of the renderer. If not specified it uses the base size from the Scale Manager.
634-
* @param {number} [resolution] - The new resolution of the renderer. If not specified it uses the resolution from the Scale Manager.
649+
* @param {number} [width] - The new width of the renderer.
650+
* @param {number} [height] - The new height of the renderer.
651+
* @param {number} [resolution] - The new resolution of the renderer.
635652
*
636653
* @return {this} This WebGLRenderer instance.
637654
*/
638655
resize: function (width, height, resolution)
639656
{
640-
if (width === undefined) { width = this.scaleManager.baseSize.width; }
641-
if (height === undefined) { height = this.scaleManager.baseSize.height; }
642-
if (resolution === undefined) { resolution = this.scaleManager.resolution; }
643-
644657
var gl = this.gl;
645658
var pipelines = this.pipelines;
646659

647660
this.width = width;
648661
this.height = height;
662+
this.resolution = resolution;
649663

650664
gl.viewport(0, 0, width, height);
651665

0 commit comments

Comments
 (0)