Skip to content

Commit dc2375d

Browse files
committed
Camera Manager will now listen for RESIZE event and resize full-sized cameras automatically
1 parent 254eef9 commit dc2375d

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/cameras/2d/CameraManager.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var Class = require('../../utils/Class');
99
var GetFastValue = require('../../utils/object/GetFastValue');
1010
var PluginCache = require('../../plugins/PluginCache');
1111
var RectangleContains = require('../../geom/rectangle/Contains');
12+
var ScaleEvents = require('../../scale/events');
1213
var SceneEvents = require('../../scene/events');
1314

1415
/**
@@ -159,6 +160,8 @@ var CameraManager = new Class({
159160
// Create a default camera
160161
this.default = new Camera(0, 0, sys.scale.width, sys.scale.height).setScene(this.scene);
161162

163+
sys.game.scale.on(ScaleEvents.RESIZE, this.onResize, this);
164+
162165
this.systems.events.once(SceneEvents.DESTROY, this.destroy, this);
163166
},
164167

@@ -645,6 +648,31 @@ var CameraManager = new Class({
645648
}
646649
},
647650

651+
/**
652+
* The event handler that manages the `resize` event dispatched by the Scale Manager.
653+
*
654+
* @method Phaser.Cameras.Scene2D.CameraManager#onResize
655+
* @since 3.18.0
656+
*
657+
* @param {Phaser.Structs.Size} gameSize - The default Game Size object. This is the un-modified game dimensions.
658+
* @param {Phaser.Structs.Size} baseSize - The base Size object. The game dimensions multiplied by the resolution. The canvas width / height values match this.
659+
*/
660+
onResize: function (gameSize, baseSize, displaySize, resolution, previousWidth, previousHeight)
661+
{
662+
for (var i = 0; i < this.cameras.length; i++)
663+
{
664+
var cam = this.cameras[i];
665+
666+
// if camera is at 0x0 and was the size of the previous game size, then we can safely assume it
667+
// should be updated to match the new game size too
668+
669+
if (cam._x === 0 && cam._y === 0 && cam._width === previousWidth && cam._height === previousHeight)
670+
{
671+
cam.setSize(baseSize.width, baseSize.height);
672+
}
673+
}
674+
},
675+
648676
/**
649677
* Resizes all cameras to the given dimensions.
650678
*

0 commit comments

Comments
 (0)