mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 05:03:37 +00:00
Camera Manager will now listen for RESIZE event and resize full-sized cameras automatically
This commit is contained in:
parent
254eef9787
commit
dc2375de70
1 changed files with 28 additions and 0 deletions
|
@ -9,6 +9,7 @@ var Class = require('../../utils/Class');
|
|||
var GetFastValue = require('../../utils/object/GetFastValue');
|
||||
var PluginCache = require('../../plugins/PluginCache');
|
||||
var RectangleContains = require('../../geom/rectangle/Contains');
|
||||
var ScaleEvents = require('../../scale/events');
|
||||
var SceneEvents = require('../../scene/events');
|
||||
|
||||
/**
|
||||
|
@ -159,6 +160,8 @@ var CameraManager = new Class({
|
|||
// Create a default camera
|
||||
this.default = new Camera(0, 0, sys.scale.width, sys.scale.height).setScene(this.scene);
|
||||
|
||||
sys.game.scale.on(ScaleEvents.RESIZE, this.onResize, this);
|
||||
|
||||
this.systems.events.once(SceneEvents.DESTROY, this.destroy, this);
|
||||
},
|
||||
|
||||
|
@ -645,6 +648,31 @@ var CameraManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* The event handler that manages the `resize` event dispatched by the Scale Manager.
|
||||
*
|
||||
* @method Phaser.Cameras.Scene2D.CameraManager#onResize
|
||||
* @since 3.18.0
|
||||
*
|
||||
* @param {Phaser.Structs.Size} gameSize - The default Game Size object. This is the un-modified game dimensions.
|
||||
* @param {Phaser.Structs.Size} baseSize - The base Size object. The game dimensions multiplied by the resolution. The canvas width / height values match this.
|
||||
*/
|
||||
onResize: function (gameSize, baseSize, displaySize, resolution, previousWidth, previousHeight)
|
||||
{
|
||||
for (var i = 0; i < this.cameras.length; i++)
|
||||
{
|
||||
var cam = this.cameras[i];
|
||||
|
||||
// if camera is at 0x0 and was the size of the previous game size, then we can safely assume it
|
||||
// should be updated to match the new game size too
|
||||
|
||||
if (cam._x === 0 && cam._y === 0 && cam._width === previousWidth && cam._height === previousHeight)
|
||||
{
|
||||
cam.setSize(baseSize.width, baseSize.height);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Resizes all cameras to the given dimensions.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue