Skip to content

Commit efc5a12

Browse files
authored
Merge pull request phaserjs#3424 from pixelscripter/master
Added callback methods to Camera2D effects: Shake, Fade and Flash
2 parents f4f88a6 + ed3dc2b commit efc5a12

1 file changed

Lines changed: 86 additions & 31 deletions

File tree

src/cameras/2d/Camera.js

Lines changed: 86 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,17 @@ var Camera = new Class({
290290
*/
291291
this._shakeOffsetY = 0;
292292

293+
/**
294+
* [description]
295+
*
296+
* @name Phaser.Cameras.Scene2D.Camera#_shakeCallback
297+
* @type {function}
298+
* @private
299+
* @default null
300+
* @since 3.3.0
301+
*/
302+
this._shakeCallback = null;
303+
293304
/**
294305
* [description]
295306
*
@@ -345,6 +356,17 @@ var Camera = new Class({
345356
*/
346357
this._fadeAlpha = 0;
347358

359+
/**
360+
* [description]
361+
*
362+
* @name Phaser.Cameras.Scene2D.Camera#_fadeCallback
363+
* @type {function}
364+
* @private
365+
* @default null
366+
* @since 3.3.0
367+
*/
368+
this._fadeCallback = null;
369+
348370
/**
349371
* [description]
350372
*
@@ -400,6 +422,17 @@ var Camera = new Class({
400422
*/
401423
this._flashAlpha = 0;
402424

425+
/**
426+
* [description]
427+
*
428+
* @name Phaser.Cameras.Scene2D.Camera#_flashCallback
429+
* @type {function}
430+
* @private
431+
* @default null
432+
* @since 3.3.0
433+
*/
434+
this._flashCallback = null;
435+
403436
/**
404437
* [description]
405438
*
@@ -685,10 +718,11 @@ var Camera = new Class({
685718
* @param {number} green - [description]
686719
* @param {number} blue - [description]
687720
* @param {number} force - [description]
721+
* @param {function} callback - [description]
688722
*
689723
* @return {Phaser.Cameras.Scene2D.Camera} This Camera instance.
690724
*/
691-
fade: function (duration, red, green, blue, force)
725+
fade: function (duration, red, green, blue, force, callback)
692726
{
693727
if (red === undefined) { red = 0; }
694728
if (green === undefined) { green = 0; }
@@ -702,6 +736,7 @@ var Camera = new Class({
702736
this._fadeRed = red;
703737
this._fadeGreen = green;
704738
this._fadeBlue = blue;
739+
this._fadeCallback = callback || null;
705740

706741
if (duration <= 0)
707742
{
@@ -725,10 +760,11 @@ var Camera = new Class({
725760
* @param {number} green - [description]
726761
* @param {number} blue - [description]
727762
* @param {number} force - [description]
763+
* @param {function} callback - [description]
728764
*
729765
* @return {Phaser.Cameras.Scene2D.Camera} This Camera instance.
730766
*/
731-
flash: function (duration, red, green, blue, force)
767+
flash: function (duration, red, green, blue, force, callback)
732768
{
733769
if (!force && this._flashAlpha > 0.0)
734770
{
@@ -742,6 +778,7 @@ var Camera = new Class({
742778
this._flashRed = red;
743779
this._flashGreen = green;
744780
this._flashBlue = blue;
781+
this._flashCallback = callback || null;
745782

746783
if (duration <= 0)
747784
{
@@ -754,6 +791,37 @@ var Camera = new Class({
754791
return this;
755792
},
756793

794+
/**
795+
* [description]
796+
*
797+
* @method Phaser.Cameras.Scene2D.Camera#shake
798+
* @since 3.0.0
799+
*
800+
* @param {number} duration - [description]
801+
* @param {number} intensity - [description]
802+
* @param {number} force - [description]
803+
* @param {function} callback - [description]
804+
*
805+
* @return {Phaser.Cameras.Scene2D.Camera} This Camera instance.
806+
*/
807+
shake: function (duration, intensity, force, callback)
808+
{
809+
if (intensity === undefined) { intensity = 0.05; }
810+
811+
if (!force && (this._shakeOffsetX !== 0 || this._shakeOffsetY !== 0))
812+
{
813+
return this;
814+
}
815+
816+
this._shakeDuration = duration;
817+
this._shakeIntensity = intensity;
818+
this._shakeOffsetX = 0;
819+
this._shakeOffsetY = 0;
820+
this._shakeCallback = callback || null;
821+
822+
return this;
823+
},
824+
757825
/**
758826
* [description]
759827
*
@@ -1170,35 +1238,6 @@ var Camera = new Class({
11701238
return this;
11711239
},
11721240

1173-
/**
1174-
* [description]
1175-
*
1176-
* @method Phaser.Cameras.Scene2D.Camera#shake
1177-
* @since 3.0.0
1178-
*
1179-
* @param {number} duration - [description]
1180-
* @param {number} intensity - [description]
1181-
* @param {number} force - [description]
1182-
*
1183-
* @return {Phaser.Cameras.Scene2D.Camera} This Camera instance.
1184-
*/
1185-
shake: function (duration, intensity, force)
1186-
{
1187-
if (intensity === undefined) { intensity = 0.05; }
1188-
1189-
if (!force && (this._shakeOffsetX !== 0 || this._shakeOffsetY !== 0))
1190-
{
1191-
return this;
1192-
}
1193-
1194-
this._shakeDuration = duration;
1195-
this._shakeIntensity = intensity;
1196-
this._shakeOffsetX = 0;
1197-
this._shakeOffsetY = 0;
1198-
1199-
return this;
1200-
},
1201-
12021241
/**
12031242
* [description]
12041243
*
@@ -1313,6 +1352,11 @@ var Camera = new Class({
13131352
{
13141353
this._flashAlpha = 0.0;
13151354
}
1355+
if (this._flashCallback !== null && this._flashAlpha === 0.0)
1356+
{
1357+
this._flashCallback();
1358+
this._flashCallback = null;
1359+
}
13161360
}
13171361

13181362
if (this._fadeAlpha > 0.0 && this._fadeAlpha < 1.0)
@@ -1323,6 +1367,11 @@ var Camera = new Class({
13231367
{
13241368
this._fadeAlpha = 1.0;
13251369
}
1370+
if (this._fadeCallback !== null && this._fadeAlpha === 1.0)
1371+
{
1372+
this._fadeCallback();
1373+
this._fadeCallback = null;
1374+
}
13261375
}
13271376

13281377
if (this._shakeDuration > 0.0)
@@ -1335,6 +1384,12 @@ var Camera = new Class({
13351384
{
13361385
this._shakeOffsetX = 0.0;
13371386
this._shakeOffsetY = 0.0;
1387+
1388+
if (this._shakeCallback !== null)
1389+
{
1390+
this._shakeCallback();
1391+
this._shakeCallback = null;
1392+
}
13381393
}
13391394
else
13401395
{

0 commit comments

Comments
 (0)