Skip to content

Commit 9006f19

Browse files
author
Jeroen Reurings
committed
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.
1 parent 4fe6a25 commit 9006f19

1 file changed

Lines changed: 87 additions & 32 deletions

File tree

src/cameras/2d/Camera.js

Lines changed: 87 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,17 @@ var Camera = new Class({
273273
*/
274274
this._shakeOffsetY = 0;
275275

276+
/**
277+
* [description]
278+
*
279+
* @name Phaser.Cameras.Scene2D.Camera#_shakeCallback
280+
* @type {function}
281+
* @private
282+
* @default undefined
283+
* @since 3.2.1
284+
*/
285+
this._shakeCallback = undefined;
286+
276287
/**
277288
* [description]
278289
*
@@ -328,6 +339,17 @@ var Camera = new Class({
328339
*/
329340
this._fadeAlpha = 0;
330341

342+
/**
343+
* [description]
344+
*
345+
* @name Phaser.Cameras.Scene2D.Camera#_fadeCallback
346+
* @type {function}
347+
* @private
348+
* @default undefined
349+
* @since 3.2.1
350+
*/
351+
this._fadeCallback = undefined;
352+
331353
/**
332354
* [description]
333355
*
@@ -383,6 +405,17 @@ var Camera = new Class({
383405
*/
384406
this._flashAlpha = 0;
385407

408+
/**
409+
* [description]
410+
*
411+
* @name Phaser.Cameras.Scene2D.Camera#_flashCallback
412+
* @type {function}
413+
* @private
414+
* @default undefined
415+
* @since 3.2.1
416+
*/
417+
this._flashCallback = undefined;
418+
386419
/**
387420
* [description]
388421
*
@@ -668,10 +701,11 @@ var Camera = new Class({
668701
* @param {number} green - [description]
669702
* @param {number} blue - [description]
670703
* @param {number} force - [description]
704+
* @param {function} callback - [description]
671705
*
672706
* @return {Phaser.Cameras.Scene2D.Camera} This Camera instance.
673707
*/
674-
fade: function (duration, red, green, blue, force)
708+
fade: function (duration, red, green, blue, force, callback)
675709
{
676710
if (red === undefined) { red = 0; }
677711
if (green === undefined) { green = 0; }
@@ -685,6 +719,7 @@ var Camera = new Class({
685719
this._fadeRed = red;
686720
this._fadeGreen = green;
687721
this._fadeBlue = blue;
722+
this._fadeCallback = callback;
688723

689724
if (duration <= 0)
690725
{
@@ -708,10 +743,11 @@ var Camera = new Class({
708743
* @param {number} green - [description]
709744
* @param {number} blue - [description]
710745
* @param {number} force - [description]
746+
* @param {function} callback - [description]
711747
*
712748
* @return {Phaser.Cameras.Scene2D.Camera} This Camera instance.
713749
*/
714-
flash: function (duration, red, green, blue, force)
750+
flash: function (duration, red, green, blue, force, callback)
715751
{
716752
if (!force && this._flashAlpha > 0.0)
717753
{
@@ -725,6 +761,7 @@ var Camera = new Class({
725761
this._flashRed = red;
726762
this._flashGreen = green;
727763
this._flashBlue = blue;
764+
this._flashCallback = callback;
728765

729766
if (duration <= 0)
730767
{
@@ -737,6 +774,37 @@ var Camera = new Class({
737774
return this;
738775
},
739776

777+
/**
778+
* [description]
779+
*
780+
* @method Phaser.Cameras.Scene2D.Camera#shake
781+
* @since 3.0.0
782+
*
783+
* @param {number} duration - [description]
784+
* @param {number} intensity - [description]
785+
* @param {number} force - [description]
786+
* @param {function} callback - [description]
787+
*
788+
* @return {Phaser.Cameras.Scene2D.Camera} This Camera instance.
789+
*/
790+
shake: function (duration, intensity, force, callback)
791+
{
792+
if (intensity === undefined) { intensity = 0.05; }
793+
794+
if (!force && (this._shakeOffsetX !== 0 || this._shakeOffsetY !== 0))
795+
{
796+
return this;
797+
}
798+
799+
this._shakeDuration = duration;
800+
this._shakeIntensity = intensity;
801+
this._shakeOffsetX = 0;
802+
this._shakeOffsetY = 0;
803+
this._shakeCallback = callback;
804+
805+
return this;
806+
},
807+
740808
/**
741809
* [description]
742810
*
@@ -1153,35 +1221,6 @@ var Camera = new Class({
11531221
return this;
11541222
},
11551223

1156-
/**
1157-
* [description]
1158-
*
1159-
* @method Phaser.Cameras.Scene2D.Camera#shake
1160-
* @since 3.0.0
1161-
*
1162-
* @param {number} duration - [description]
1163-
* @param {number} intensity - [description]
1164-
* @param {number} force - [description]
1165-
*
1166-
* @return {Phaser.Cameras.Scene2D.Camera} This Camera instance.
1167-
*/
1168-
shake: function (duration, intensity, force)
1169-
{
1170-
if (intensity === undefined) { intensity = 0.05; }
1171-
1172-
if (!force && (this._shakeOffsetX !== 0 || this._shakeOffsetY !== 0))
1173-
{
1174-
return this;
1175-
}
1176-
1177-
this._shakeDuration = duration;
1178-
this._shakeIntensity = intensity;
1179-
this._shakeOffsetX = 0;
1180-
this._shakeOffsetY = 0;
1181-
1182-
return this;
1183-
},
1184-
11851224
/**
11861225
* [description]
11871226
*
@@ -1296,6 +1335,11 @@ var Camera = new Class({
12961335
{
12971336
this._flashAlpha = 0.0;
12981337
}
1338+
if (this._flashCallback !== undefined && this._flashAlpha === 0.0)
1339+
{
1340+
this._flashCallback();
1341+
this._flashCallback = undefined;
1342+
}
12991343
}
13001344

13011345
if (this._fadeAlpha > 0.0 && this._fadeAlpha < 1.0)
@@ -1306,6 +1350,11 @@ var Camera = new Class({
13061350
{
13071351
this._fadeAlpha = 1.0;
13081352
}
1353+
if (this._fadeCallback !== undefined && this._fadeAlpha === 1.0)
1354+
{
1355+
this._fadeCallback();
1356+
this._fadeCallback = undefined;
1357+
}
13091358
}
13101359

13111360
if (this._shakeDuration > 0.0)
@@ -1318,12 +1367,18 @@ var Camera = new Class({
13181367
{
13191368
this._shakeOffsetX = 0.0;
13201369
this._shakeOffsetY = 0.0;
1370+
1371+
if (this._shakeCallback !== undefined)
1372+
{
1373+
this._shakeCallback();
1374+
this._shakeCallback = undefined;
1375+
}
13211376
}
13221377
else
13231378
{
13241379
this._shakeOffsetX = (Math.random() * intensity * this.width * 2 - intensity * this.width) * this.zoom;
13251380
this._shakeOffsetY = (Math.random() * intensity * this.height * 2 - intensity * this.height) * this.zoom;
1326-
1381+
13271382
if (this.roundPixels)
13281383
{
13291384
this._shakeOffsetX |= 0;

0 commit comments

Comments
 (0)