Added all Camera events

This commit is contained in:
Richard Davey 2019-01-15 23:36:52 +00:00
parent 95dde9a320
commit c29c8c65b4
16 changed files with 216 additions and 102 deletions

View file

@ -8,6 +8,7 @@ var Class = require('../../utils/Class');
var Components = require('../../gameobjects/components');
var DegToRad = require('../../math/DegToRad');
var EventEmitter = require('eventemitter3');
var Events = require('./events');
var Rectangle = require('../../geom/rectangle/Rectangle');
var TransformMatrix = require('../../gameobjects/components/TransformMatrix');
var ValueToColor = require('../../display/color/ValueToColor');
@ -1502,13 +1503,6 @@ var BaseCamera = new Class({
this._customViewport = custom;
},
/**
* This event is fired when a camera is destroyed by the Camera Manager.
*
* @event CameraDestroyEvent
* @param {Phaser.Cameras.Scene2D.BaseCamera} camera - The camera that was destroyed.
*/
/**
* Destroys this Camera instance and its internal properties and references.
* Once destroyed you cannot use this Camera again, even if re-added to a Camera Manager.
@ -1519,12 +1513,12 @@ var BaseCamera = new Class({
* rather than calling this method directly.
*
* @method Phaser.Cameras.Scene2D.BaseCamera#destroy
* @fires CameraDestroyEvent
* @fires Phaser.Cameras.Scene2D.Events#DESTROY
* @since 3.0.0
*/
destroy: function ()
{
this.emit('cameradestroy', this);
this.emit(Events.DESTROY, this);
this.removeAllListeners();

View file

@ -6,6 +6,7 @@
var Clamp = require('../../../math/Clamp');
var Class = require('../../../utils/Class');
var Events = require('../events');
/**
* @classdesc
@ -156,32 +157,12 @@ var Flash = new Class({
this._onUpdateScope;
},
/**
* This event is fired when the flash effect begins to run on a camera.
*
* @event CameraFlashStartEvent
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
* @param {Phaser.Cameras.Scene2D.Effects.Flash} effect - A reference to the effect instance.
* @param {integer} duration - The duration of the effect.
* @param {integer} red - The red color channel value.
* @param {integer} green - The green color channel value.
* @param {integer} blue - The blue color channel value.
*/
/**
* This event is fired when the flash effect completes.
*
* @event CameraFlashCompleteEvent
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
* @param {Phaser.Cameras.Scene2D.Effects.Flash} effect - A reference to the effect instance.
*/
/**
* Flashes the Camera to or from the given color over the duration specified.
*
* @method Phaser.Cameras.Scene2D.Effects.Flash#start
* @fires CameraFlashStartEvent
* @fires CameraFlashCompleteEvent
* @fires Phaser.Cameras.Scene2D.Events#FLASH_START
* @fires Phaser.Cameras.Scene2D.Events#FLASH_COMPLETE
* @since 3.5.0
*
* @param {integer} [duration=250] - The duration of the effect in milliseconds.
@ -224,7 +205,7 @@ var Flash = new Class({
this._onUpdate = callback;
this._onUpdateScope = context;
this.camera.emit('cameraflashstart', this.camera, this, duration, red, green, blue);
this.camera.emit(Events.FLASH_START, this.camera, this, duration, red, green, blue);
return this.camera;
},
@ -325,6 +306,7 @@ var Flash = new Class({
* Called internally when the effect completes.
*
* @method Phaser.Cameras.Scene2D.Effects.Flash#effectComplete
* @fires Phaser.Cameras.Scene2D.Events#FLASH_COMPLETE
* @since 3.5.0
*/
effectComplete: function ()
@ -334,7 +316,7 @@ var Flash = new Class({
this.isRunning = false;
this.camera.emit('cameraflashcomplete', this.camera, this);
this.camera.emit(Events.FLASH_COMPLETE, this.camera, this);
},
/**

View file

@ -6,8 +6,9 @@
var Clamp = require('../../../math/Clamp');
var Class = require('../../../utils/Class');
var Vector2 = require('../../../math/Vector2');
var EaseMap = require('../../../math/easing/EaseMap');
var Events = require('../events');
var Vector2 = require('../../../math/Vector2');
/**
* @classdesc
@ -153,32 +154,13 @@ var Pan = new Class({
this._onUpdateScope;
},
/**
* This event is fired when the pan effect begins to run on a camera.
*
* @event CameraPanStartEvent
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
* @param {Phaser.Cameras.Scene2D.Effects.Pan} effect - A reference to the effect instance.
* @param {integer} duration - The duration of the effect.
* @param {number} x - The destination scroll x coordinate.
* @param {number} y - The destination scroll y coordinate.
*/
/**
* This event is fired when the pan effect completes.
*
* @event CameraPanCompleteEvent
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
* @param {Phaser.Cameras.Scene2D.Effects.Pan} effect - A reference to the effect instance.
*/
/**
* This effect will scroll the Camera so that the center of its viewport finishes at the given destination,
* over the duration and with the ease specified.
*
* @method Phaser.Cameras.Scene2D.Effects.Pan#start
* @fires CameraPanStartEvent
* @fires CameraPanCompleteEvent
* @fires Phaser.Cameras.Scene2D.Events#PAN_START
* @fires Phaser.Cameras.Scene2D.Events#PAN_COMPLETE
* @since 3.11.0
*
* @param {number} x - The destination x coordinate to scroll the center of the Camera viewport to.
@ -236,7 +218,7 @@ var Pan = new Class({
this._onUpdate = callback;
this._onUpdateScope = context;
this.camera.emit('camerapanstart', this.camera, this, duration, x, y);
this.camera.emit(Events.PAN_START, this.camera, this, duration, x, y);
return cam;
},
@ -298,6 +280,7 @@ var Pan = new Class({
* Called internally when the effect completes.
*
* @method Phaser.Cameras.Scene2D.Effects.Pan#effectComplete
* @fires Phaser.Cameras.Scene2D.Events#PAN_COMPLETE
* @since 3.11.0
*/
effectComplete: function ()
@ -307,7 +290,7 @@ var Pan = new Class({
this.isRunning = false;
this.camera.emit('camerapancomplete', this.camera, this);
this.camera.emit(Events.PAN_COMPLETE, this.camera, this);
},
/**

View file

@ -6,6 +6,7 @@
var Clamp = require('../../../math/Clamp');
var Class = require('../../../utils/Class');
var Events = require('../events');
var Vector2 = require('../../../math/Vector2');
/**
@ -146,30 +147,12 @@ var Shake = new Class({
this._onUpdateScope;
},
/**
* This event is fired when the shake effect begins to run on a camera.
*
* @event CameraShakeStartEvent
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
* @param {Phaser.Cameras.Scene2D.Effects.Shake} effect - A reference to the effect instance.
* @param {integer} duration - The duration of the effect.
* @param {number} intensity - The intensity of the effect.
*/
/**
* This event is fired when the shake effect completes.
*
* @event CameraShakeCompleteEvent
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
* @param {Phaser.Cameras.Scene2D.Effects.Shake} effect - A reference to the effect instance.
*/
/**
* Shakes the Camera by the given intensity over the duration specified.
*
* @method Phaser.Cameras.Scene2D.Effects.Shake#start
* @fires CameraShakeStartEvent
* @fires CameraShakeCompleteEvent
* @fires Phaser.Cameras.Scene2D.Events#SHAKE_START
* @fires Phaser.Cameras.Scene2D.Events#SHAKE_COMPLETE
* @since 3.5.0
*
* @param {integer} [duration=100] - The duration of the effect in milliseconds.
@ -214,7 +197,7 @@ var Shake = new Class({
this._onUpdate = callback;
this._onUpdateScope = context;
this.camera.emit('camerashakestart', this.camera, this, duration, intensity);
this.camera.emit(Events.SHAKE_START, this.camera, this, duration, intensity);
return this.camera;
},
@ -284,6 +267,7 @@ var Shake = new Class({
* Called internally when the effect completes.
*
* @method Phaser.Cameras.Scene2D.Effects.Shake#effectComplete
* @fires Phaser.Cameras.Scene2D.Events#SHAKE_COMPLETE
* @since 3.5.0
*/
effectComplete: function ()
@ -296,7 +280,7 @@ var Shake = new Class({
this.isRunning = false;
this.camera.emit('camerashakecomplete', this.camera, this);
this.camera.emit(Events.SHAKE_COMPLETE, this.camera, this);
},
/**

View file

@ -7,6 +7,7 @@
var Clamp = require('../../../math/Clamp');
var Class = require('../../../utils/Class');
var EaseMap = require('../../../math/easing/EaseMap');
var Events = require('../events');
/**
* @classdesc
@ -138,30 +139,12 @@ var Zoom = new Class({
this._onUpdateScope;
},
/**
* This event is fired when the Zoom effect begins to run on a camera.
*
* @event CameraZoomStartEvent
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
* @param {Phaser.Cameras.Scene2D.Effects.Zoom} effect - A reference to the effect instance.
* @param {integer} duration - The duration of the effect.
* @param {number} zoom - The destination zoom value.
*/
/**
* This event is fired when the Zoom effect completes.
*
* @event CameraZoomCompleteEvent
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
* @param {Phaser.Cameras.Scene2D.Effects.Zoom} effect - A reference to the effect instance.
*/
/**
* This effect will zoom the Camera to the given scale, over the duration and with the ease specified.
*
* @method Phaser.Cameras.Scene2D.Effects.Zoom#start
* @fires CameraZoomStartEvent
* @fires CameraZoomCompleteEvent
* @fires Phaser.Cameras.Scene2D.Events#ZOOM_START
* @fires Phaser.Cameras.Scene2D.Events#ZOOM_COMPLETE
* @since 3.11.0
*
* @param {number} zoom - The target Camera zoom value.
@ -215,7 +198,7 @@ var Zoom = new Class({
this._onUpdate = callback;
this._onUpdateScope = context;
this.camera.emit('camerazoomstart', this.camera, this, duration, zoom);
this.camera.emit(Events.ZOOM_START, this.camera, this, duration, zoom);
return cam;
},
@ -266,6 +249,7 @@ var Zoom = new Class({
* Called internally when the effect completes.
*
* @method Phaser.Cameras.Scene2D.Effects.Zoom#effectComplete
* @fires Phaser.Cameras.Scene2D.Events#ZOOM_COMPLETE
* @since 3.11.0
*/
effectComplete: function ()
@ -275,7 +259,7 @@ var Zoom = new Class({
this.isRunning = false;
this.camera.emit('camerazoomcomplete', this.camera, this);
this.camera.emit(Events.ZOOM_COMPLETE, this.camera, this);
},
/**

View file

@ -0,0 +1,16 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Destroy Camera Event.
*
* This event is dispatched by a Camera instance when it is destroyed by the Camera Manager.
*
* @event Phaser.Cameras.Scene2D.Events#DESTROY
*
* @param {Phaser.Cameras.Scene2D.BaseCamera} camera - The camera that was destroyed.
*/
module.exports = 'cameradestroy';

View file

@ -0,0 +1,17 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Camera Flash Complete Event.
*
* This event is dispatched by a Camera instance when the Flash Effect completes.
*
* @event Phaser.Cameras.Scene2D.Events#FLASH_COMPLETE
*
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
* @param {Phaser.Cameras.Scene2D.Effects.Flash} effect - A reference to the effect instance.
*/
module.exports = 'cameraflashcomplete';

View file

@ -0,0 +1,21 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Camera Flash Start Event.
*
* This event is dispatched by a Camera instance when the Flash Effect starts.
*
* @event Phaser.Cameras.Scene2D.Events#FLASH_START
*
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
* @param {Phaser.Cameras.Scene2D.Effects.Flash} effect - A reference to the effect instance.
* @param {integer} duration - The duration of the effect.
* @param {integer} red - The red color channel value.
* @param {integer} green - The green color channel value.
* @param {integer} blue - The blue color channel value.
*/
module.exports = 'cameraflashstart';

View file

@ -0,0 +1,17 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Camera Pan Complete Event.
*
* This event is dispatched by a Camera instance when the Pan Effect completes.
*
* @event Phaser.Cameras.Scene2D.Events#PAN_COMPLETE
*
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
* @param {Phaser.Cameras.Scene2D.Effects.Pan} effect - A reference to the effect instance.
*/
module.exports = 'camerapancomplete';

View file

@ -0,0 +1,20 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Camera Pan Start Event.
*
* This event is dispatched by a Camera instance when the Pan Effect starts.
*
* @event Phaser.Cameras.Scene2D.Events#PAN_START
*
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
* @param {Phaser.Cameras.Scene2D.Effects.Pan} effect - A reference to the effect instance.
* @param {integer} duration - The duration of the effect.
* @param {number} x - The destination scroll x coordinate.
* @param {number} y - The destination scroll y coordinate.
*/
module.exports = 'camerapanstart';

View file

@ -0,0 +1,17 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Camera Shake Complete Event.
*
* This event is dispatched by a Camera instance when the Shake Effect completes.
*
* @event Phaser.Cameras.Scene2D.Events#SHAKE_COMPLETE
*
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
* @param {Phaser.Cameras.Scene2D.Effects.Shake} effect - A reference to the effect instance.
*/
module.exports = 'camerashakecomplete';

View file

@ -0,0 +1,19 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Camera Shake Start Event.
*
* This event is dispatched by a Camera instance when the Shake Effect starts.
*
* @event Phaser.Cameras.Scene2D.Events#SHAKE_START
*
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
* @param {Phaser.Cameras.Scene2D.Effects.Shake} effect - A reference to the effect instance.
* @param {integer} duration - The duration of the effect.
* @param {number} intensity - The intensity of the effect.
*/
module.exports = 'camerashakestart';

View file

@ -0,0 +1,17 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Camera Zoom Complete Event.
*
* This event is dispatched by a Camera instance when the Zoom Effect completes.
*
* @event Phaser.Cameras.Scene2D.Events#ZOOM_COMPLETE
*
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
* @param {Phaser.Cameras.Scene2D.Effects.Zoom} effect - A reference to the effect instance.
*/
module.exports = 'camerazoomcomplete';

View file

@ -0,0 +1,19 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Camera Zoom Start Event.
*
* This event is dispatched by a Camera instance when the Zoom Effect starts.
*
* @event Phaser.Cameras.Scene2D.Events#ZOOM_START
*
* @param {Phaser.Cameras.Scene2D.Camera} camera - The camera that the effect began on.
* @param {Phaser.Cameras.Scene2D.Effects.Zoom} effect - A reference to the effect instance.
* @param {integer} duration - The duration of the effect.
* @param {number} zoom - The destination zoom value.
*/
module.exports = 'camerazoomstart';

View file

@ -0,0 +1,23 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2019 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* @namespace Phaser.Cameras.Scene2D.Events
*/
module.exports = {
DESTROY: require('./DESTROY_EVENT'),
FLASH_COMPLETE: require('./FLASH_COMPLETE_EVENT'),
FLASH_START: require('./FLASH_START_EVENT'),
PAN_COMPLETE: require('./PAN_COMPLETE_EVENT'),
PAN_START: require('./PAN_START_EVENT'),
SHAKE_COMPLETE: require('./SHAKE_COMPLETE_EVENT'),
SHAKE_START: require('./SHAKE_START_EVENT'),
ZOOM_COMPLETE: require('./ZOOM_COMPLETE_EVENT'),
ZOOM_START: require('./ZOOM_START_EVENT')
};

View file

@ -12,6 +12,7 @@ module.exports = {
Camera: require('./Camera'),
CameraManager: require('./CameraManager'),
Effects: require('./effects')
Effects: require('./effects'),
Events: require('./events')
};