Skip to content

Commit b6a1033

Browse files
committed
Fixed Camera FX for scaled camera sizes
1 parent 14ba51d commit b6a1033

5 files changed

Lines changed: 21 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@
1212
* `Camera.x` and `Camera.y` have been turned into getters / setters, mapped to the internal private values `_x` and `_y` respectively. This is so that setting the Camera viewport position directly will now update the new internal resolution calculation vars too.
1313
* `Camera.setScene` will now set the Cameras `resolution` property at the same time and update the internal viewport vars.
1414

15+
### Game Config Resolution Specific Bug Fixes
16+
17+
Setting the `resolution` property in the Game Config to a value other than 1 would cause various errors in the API. The following have been fixed:
18+
19+
* The game canvas would be sized incorrectly, unless you had enabled auto resizing. It now scales the canvas to the size given, maintaining the resolution. Fix #3468 (thanks @Legomite)
20+
* Cameras with background colors set would display the filled color area at the wrong size. Camera fills now respect the resolution.
21+
* The Camera Fade Effect would display the fade fill rectangle at the wrong size. Camera fades now respect the resolution.
22+
* The Camera Flash Effect would display the fade fill rectangle at the wrong size. Camera flashes now respect the resolution.
23+
* The Camera Shake Effect would shake the Camera using the wrong width values. Camera Shakes now respect the resolution.
24+
* Input calculations would not factor in the Game Resolution correctly. If a Camera viewport was not at 0x0 or not the full size, or the Camera was rotated or zoomed, the input areas would be wrong if `resolution` was > 1. These are now factored in correctly and changing the resolution no longer breaks input. Fix #3606 (thanks @Secretmapper)
25+
1526
### Bug Fixes
1627

1728
* If an AudioFile failed to load and throw an incomplete error, it would cause the console.log to crash JavaScript when trying to log the error. It now only logs the message if it exists. Fix #3830 (thanks @kelostrada)

src/cameras/2d/effects/Fade.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ var Fade = new Class({
337337
var camera = this.camera;
338338

339339
ctx.fillStyle = 'rgba(' + this.red + ',' + this.green + ',' + this.blue + ',' + this.alpha + ')';
340-
ctx.fillRect(camera.x, camera.y, camera.width, camera.height);
340+
ctx.fillRect(camera._cx, camera._cy, camera._cw, camera._ch);
341341

342342
return true;
343343
},
@@ -367,7 +367,7 @@ var Fade = new Class({
367367

368368
pipeline.batchFillRect(
369369
0, 0, 1, 1, 0,
370-
camera.x, camera.y, camera.width, camera.height,
370+
camera._cx, camera._cy, camera._cw, camera._ch,
371371
getTintFunction(red, green, blue, 1),
372372
this.alpha,
373373
1, 0, 0, 1, 0, 0,

src/cameras/2d/effects/Flash.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ var Flash = new Class({
284284
var camera = this.camera;
285285

286286
ctx.fillStyle = 'rgba(' + this.red + ',' + this.green + ',' + this.blue + ',' + this.alpha + ')';
287-
ctx.fillRect(camera.x, camera.y, camera.width, camera.height);
287+
ctx.fillRect(camera._cx, camera._cy, camera._cw, camera._ch);
288288

289289
return true;
290290
},
@@ -314,7 +314,7 @@ var Flash = new Class({
314314

315315
pipeline.batchFillRect(
316316
0, 0, 1, 1, 0,
317-
camera.x, camera.y, camera.width, camera.height,
317+
camera._cx, camera._cy, camera._cw, camera._ch,
318318
getTintFunction(red, green, blue, 1),
319319
this.alpha,
320320
1, 0, 0, 1, 0, 0,

src/cameras/2d/effects/Shake.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ var Shake = new Class({
261261
if (this._elapsed < this.duration)
262262
{
263263
var intensity = this.intensity;
264-
var width = this.camera.width;
265-
var height = this.camera.height;
264+
var width = this.camera._cw;
265+
var height = this.camera._ch;
266266
var zoom = this.camera.zoom;
267267

268268
this._offsetX = (Math.random() * intensity.x * width * 2 - intensity.x * width) * zoom;

src/renderer/canvas/CanvasRenderer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,15 @@ var CanvasRenderer = new Class({
380380
*/
381381
render: function (scene, children, interpolationPercentage, camera)
382382
{
383-
var ctx = scene.sys.context;
384-
var scissor = (camera.x !== 0 || camera.y !== 0 || camera.width !== ctx.canvas.width || camera.height !== ctx.canvas.height);
385-
var list = children.list;
386-
387383
var cx = camera._cx;
388384
var cy = camera._cy;
389385
var cw = camera._cw;
390386
var ch = camera._ch;
391387

388+
var ctx = scene.sys.context;
389+
var scissor = (cx !== 0 || cy !== 0 || cw !== ctx.canvas.width || ch !== ctx.canvas.height);
390+
var list = children.list;
391+
392392
this.currentContext = ctx;
393393

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

0 commit comments

Comments
 (0)