Added callbacks to Shake, Fade and Flash effects, so you don't have to use a delayed call to trigger something after an effect is completed;

Moved the shake function next to the other effect functions.
This commit is contained in:
Jeroen Reurings 2018-03-19 16:21:48 +01:00
parent 4fe6a25117
commit 9006f19f41

View file

@ -273,6 +273,17 @@ var Camera = new Class({
*/
this._shakeOffsetY = 0;
/**
* [description]
*
* @name Phaser.Cameras.Scene2D.Camera#_shakeCallback
* @type {function}
* @private
* @default undefined
* @since 3.2.1
*/
this._shakeCallback = undefined;
/**
* [description]
*
@ -328,6 +339,17 @@ var Camera = new Class({
*/
this._fadeAlpha = 0;
/**
* [description]
*
* @name Phaser.Cameras.Scene2D.Camera#_fadeCallback
* @type {function}
* @private
* @default undefined
* @since 3.2.1
*/
this._fadeCallback = undefined;
/**
* [description]
*
@ -383,6 +405,17 @@ var Camera = new Class({
*/
this._flashAlpha = 0;
/**
* [description]
*
* @name Phaser.Cameras.Scene2D.Camera#_flashCallback
* @type {function}
* @private
* @default undefined
* @since 3.2.1
*/
this._flashCallback = undefined;
/**
* [description]
*
@ -668,10 +701,11 @@ var Camera = new Class({
* @param {number} green - [description]
* @param {number} blue - [description]
* @param {number} force - [description]
* @param {function} callback - [description]
*
* @return {Phaser.Cameras.Scene2D.Camera} This Camera instance.
*/
fade: function (duration, red, green, blue, force)
fade: function (duration, red, green, blue, force, callback)
{
if (red === undefined) { red = 0; }
if (green === undefined) { green = 0; }
@ -685,6 +719,7 @@ var Camera = new Class({
this._fadeRed = red;
this._fadeGreen = green;
this._fadeBlue = blue;
this._fadeCallback = callback;
if (duration <= 0)
{
@ -708,10 +743,11 @@ var Camera = new Class({
* @param {number} green - [description]
* @param {number} blue - [description]
* @param {number} force - [description]
* @param {function} callback - [description]
*
* @return {Phaser.Cameras.Scene2D.Camera} This Camera instance.
*/
flash: function (duration, red, green, blue, force)
flash: function (duration, red, green, blue, force, callback)
{
if (!force && this._flashAlpha > 0.0)
{
@ -725,6 +761,7 @@ var Camera = new Class({
this._flashRed = red;
this._flashGreen = green;
this._flashBlue = blue;
this._flashCallback = callback;
if (duration <= 0)
{
@ -737,6 +774,37 @@ var Camera = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Cameras.Scene2D.Camera#shake
* @since 3.0.0
*
* @param {number} duration - [description]
* @param {number} intensity - [description]
* @param {number} force - [description]
* @param {function} callback - [description]
*
* @return {Phaser.Cameras.Scene2D.Camera} This Camera instance.
*/
shake: function (duration, intensity, force, callback)
{
if (intensity === undefined) { intensity = 0.05; }
if (!force && (this._shakeOffsetX !== 0 || this._shakeOffsetY !== 0))
{
return this;
}
this._shakeDuration = duration;
this._shakeIntensity = intensity;
this._shakeOffsetX = 0;
this._shakeOffsetY = 0;
this._shakeCallback = callback;
return this;
},
/**
* [description]
*
@ -1153,35 +1221,6 @@ var Camera = new Class({
return this;
},
/**
* [description]
*
* @method Phaser.Cameras.Scene2D.Camera#shake
* @since 3.0.0
*
* @param {number} duration - [description]
* @param {number} intensity - [description]
* @param {number} force - [description]
*
* @return {Phaser.Cameras.Scene2D.Camera} This Camera instance.
*/
shake: function (duration, intensity, force)
{
if (intensity === undefined) { intensity = 0.05; }
if (!force && (this._shakeOffsetX !== 0 || this._shakeOffsetY !== 0))
{
return this;
}
this._shakeDuration = duration;
this._shakeIntensity = intensity;
this._shakeOffsetX = 0;
this._shakeOffsetY = 0;
return this;
},
/**
* [description]
*
@ -1296,6 +1335,11 @@ var Camera = new Class({
{
this._flashAlpha = 0.0;
}
if (this._flashCallback !== undefined && this._flashAlpha === 0.0)
{
this._flashCallback();
this._flashCallback = undefined;
}
}
if (this._fadeAlpha > 0.0 && this._fadeAlpha < 1.0)
@ -1306,6 +1350,11 @@ var Camera = new Class({
{
this._fadeAlpha = 1.0;
}
if (this._fadeCallback !== undefined && this._fadeAlpha === 1.0)
{
this._fadeCallback();
this._fadeCallback = undefined;
}
}
if (this._shakeDuration > 0.0)
@ -1318,12 +1367,18 @@ var Camera = new Class({
{
this._shakeOffsetX = 0.0;
this._shakeOffsetY = 0.0;
if (this._shakeCallback !== undefined)
{
this._shakeCallback();
this._shakeCallback = undefined;
}
}
else
{
this._shakeOffsetX = (Math.random() * intensity * this.width * 2 - intensity * this.width) * this.zoom;
this._shakeOffsetY = (Math.random() * intensity * this.height * 2 - intensity * this.height) * this.zoom;
if (this.roundPixels)
{
this._shakeOffsetX |= 0;