Skip to content

Commit 9b27413

Browse files
committed
Resolution affecting camera display
1 parent 8bce7ea commit 9b27413

6 files changed

Lines changed: 34 additions & 29 deletions

File tree

src/cameras/2d/Camera.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ var Camera = new Class({
836836
* @param {number} baseScale - [description]
837837
*
838838
*/
839-
preRender: function (baseScale)
839+
preRender: function (baseScale, resolution)
840840
{
841841
var width = this.width;
842842
var height = this.height;
@@ -888,6 +888,7 @@ var Camera = new Class({
888888
}
889889

890890
matrix.loadIdentity();
891+
matrix.scale(resolution, resolution);
891892
matrix.translate(this.x + originX, this.y + originY);
892893
matrix.rotate(this.rotation);
893894
matrix.scale(zoom, zoom);

src/cameras/2d/CameraManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ var CameraManager = new Class({
381381
{
382382
var camera = cameras[i];
383383

384-
camera.preRender(baseScale);
384+
camera.preRender(baseScale, renderer.config.resolution);
385385

386386
renderer.render(this.scene, children, interpolation, camera);
387387
}

src/gameobjects/text/static/Text.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,7 @@ var Text = new Class({
907907
var canvas = this.canvas;
908908
var context = this.context;
909909
var style = this.style;
910+
var resolution = this.resolution;
910911
var size = style.metrics;
911912

912913
style.syncFont(canvas, context);
@@ -940,8 +941,8 @@ var Text = new Class({
940941

941942
this.updateDisplayOrigin();
942943

943-
w *= this.resolution;
944-
h *= this.resolution;
944+
w *= resolution;
945+
h *= resolution;
945946

946947
w = Math.max(w, 1);
947948
h = Math.max(h, 1);
@@ -958,6 +959,7 @@ var Text = new Class({
958959
}
959960

960961
context.save();
962+
//context.scale(resolution, resolution);
961963

962964
if (style.backgroundColor)
963965
{

src/gameobjects/text/static/TextCanvasRenderer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var TextCanvasRenderer = function (renderer, src, interpolationPercentage, camer
2828
}
2929

3030
var ctx = renderer.currentContext;
31+
var resolution = src.resolution;
3132

3233
// Blend Mode
3334
if (renderer.currentBlendMode !== src.blendMode)
@@ -52,6 +53,7 @@ var TextCanvasRenderer = function (renderer, src, interpolationPercentage, camer
5253
var canvas = src.canvas;
5354

5455
ctx.save();
56+
//ctx.scale(1.0 / resolution, 1.0 / resolution);
5557
ctx.translate(src.x - camera.scrollX * src.scrollFactorX, src.y - camera.scrollY * src.scrollFactorY);
5658
ctx.rotate(src.rotation);
5759
ctx.scale(src.scaleX, src.scaleY);

src/renderer/canvas/CanvasRenderer.js

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ var CanvasRenderer = new Class({
6565
* @type {number}
6666
* @since 3.0.0
6767
*/
68-
this.width = game.config.width * game.config.resolution;
68+
this.width = game.config.width;
6969

7070
/**
7171
* [description]
@@ -74,16 +74,22 @@ var CanvasRenderer = new Class({
7474
* @type {number}
7575
* @since 3.0.0
7676
*/
77-
this.height = game.config.height * game.config.resolution;
77+
this.height = game.config.height;
7878

7979
/**
8080
* [description]
8181
*
82-
* @name Phaser.Renderer.Canvas.CanvasRenderer#resolution
83-
* @type {number}
82+
* @name Phaser.Renderer.Canvas.CanvasRenderer#config
83+
* @type {object}
8484
* @since 3.0.0
8585
*/
86-
this.resolution = game.config.resolution;
86+
this.config = {
87+
clearBeforeRender: game.config.clearBeforeRender,
88+
pixelArt: game.config.pixelArt,
89+
backgroundColor: game.config.backgroundColor,
90+
resolution: game.config.resolution,
91+
autoResize: game.config.autoResize
92+
};
8793

8894
/**
8995
* [description]
@@ -112,15 +118,6 @@ var CanvasRenderer = new Class({
112118
*/
113119
this.gameContext = this.gameCanvas.getContext('2d');
114120

115-
/**
116-
* [description]
117-
*
118-
* @name Phaser.Renderer.Canvas.CanvasRenderer#gameConfig
119-
* @type {Phaser.Boot.Config}
120-
* @since 3.0.0
121-
*/
122-
this.gameConfig = game.config;
123-
124121
/**
125122
* [description]
126123
*
@@ -242,18 +239,18 @@ var CanvasRenderer = new Class({
242239
*/
243240
resize: function (width, height)
244241
{
245-
var res = this.game.config.resolution;
246-
247-
this.width = width * res;
248-
this.height = height * res;
242+
var resolution = this.config.resolution;
249243

244+
this.width = width * resolution;
245+
this.height = height * resolution;
246+
250247
this.gameCanvas.width = this.width;
251248
this.gameCanvas.height = this.height;
252249

253-
if (this.autoResize)
250+
if (this.config.autoResize)
254251
{
255-
this.gameCanvas.style.width = (this.width / res) + 'px';
256-
this.gameCanvas.style.height = (this.height / res) + 'px';
252+
this.gameCanvas.style.width = (this.width / resolution) + 'px';
253+
this.gameCanvas.style.height = (this.height / resolution) + 'px';
257254
}
258255

259256
// Resizing a canvas will reset imageSmoothingEnabled (and probably other properties)
@@ -349,7 +346,7 @@ var CanvasRenderer = new Class({
349346
preRender: function ()
350347
{
351348
var ctx = this.gameContext;
352-
var config = this.gameConfig;
349+
var config = this.config;
353350

354351
var width = this.width;
355352
var height = this.height;
@@ -384,6 +381,7 @@ var CanvasRenderer = new Class({
384381
var ctx = scene.sys.context;
385382
var scissor = (camera.x !== 0 || camera.y !== 0 || camera.width !== ctx.canvas.width || camera.height !== ctx.canvas.height);
386383
var list = children.list;
384+
var resolution = this.config.resolution;
387385

388386
this.currentContext = ctx;
389387

@@ -415,7 +413,7 @@ var CanvasRenderer = new Class({
415413
{
416414
ctx.save();
417415
ctx.beginPath();
418-
ctx.rect(camera.x, camera.y, camera.width, camera.height);
416+
ctx.rect(camera.x * resolution, camera.y * resolution, camera.width * resolution, camera.height * resolution);
419417
ctx.clip();
420418
}
421419

src/renderer/webgl/WebGLRenderer.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ var WebGLRenderer = new Class({
430430
this.canvas.width = this.width;
431431
this.canvas.height = this.height;
432432

433-
//if (this.config.autoResize)
433+
if (this.config.autoResize)
434434
{
435435
this.canvas.style.width = (this.width / resolution) + 'px';
436436
this.canvas.style.height = (this.height / resolution) + 'px';
@@ -1217,7 +1217,9 @@ var WebGLRenderer = new Class({
12171217
*/
12181218
preRenderCamera: function (camera)
12191219
{
1220-
this.pushScissor(camera.x, camera.y, camera.width, camera.height);
1220+
var resolution = this.config.resolution;
1221+
1222+
this.pushScissor(camera.x * resolution, camera.y * resolution, camera.width * resolution, camera.height * resolution);
12211223

12221224
if (camera.backgroundColor.alphaGL > 0)
12231225
{

0 commit comments

Comments
 (0)