Skip to content

Commit 75bb9d9

Browse files
committed
Camera.fadeIn is a new method that will fade the camera in from a given color (black by default) and then optionally invoke a callback. This is the same as using Camera.flash but with an easier to grok method name. Fix phaserjs#3412
1 parent 00a3f71 commit 75bb9d9

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ A special mention must go to @orblazer for their outstanding assistance in helpi
2727
* Camera.shake now has an optional `callback` argument that is invoked when the effect completes (thanks @pixelscripter)
2828
* Camera.fade now has an optional `callback` argument that is invoked when the effect completes (thanks @pixelscripter)
2929
* Camera.flash now has an optional `callback` argument that is invoked when the effect completes (thanks @pixelscripter)
30+
* Camera.fadeIn is a new method that will fade the camera in from a given color (black by default) and then optionally invoke a callback. This is the same as using Camera.flash but with an easier to grok method name. Fix #3412 (thanks @Jerenaux)
31+
* Camera.fadeOut is a new method that will fade the camera out to a given color (black by default) and then optionally invoke a callback. This is the same as using Camera.fade but with an easier to grok method name. Fix #3412 (thanks @Jerenaux)
3032

3133
### Bug Fixes
3234

src/cameras/2d/Camera.js

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,53 @@ var Camera = new Class({
707707
return culledObjects;
708708
},
709709

710+
/**
711+
* Fades the Camera in from the given color over the duration specified.
712+
*
713+
* @method Phaser.Cameras.Scene2D.Camera#fadeIn
714+
* @since 3.3.0
715+
*
716+
* @param {number} duration - The duration of the effect in milliseconds.
717+
* @param {function} [callback] - An optional callback to invoke when the fade completes. Will be sent one argument - a reference to this camera.
718+
* @param {number} [red=0] - The value to fade the red channel from. A value between 0 and 1.
719+
* @param {number} [green=0] - The value to fade the green channel from. A value between 0 and 1.
720+
* @param {number} [blue=0] - The value to fade the blue channel from. A value between 0 and 1.
721+
*
722+
* @return {Phaser.Cameras.Scene2D.Camera} This Camera instance.
723+
*/
724+
fadeIn: function (duration, callback, red, green, blue)
725+
{
726+
if (red === undefined) { red = 0; }
727+
if (green === undefined) { green = 0; }
728+
if (blue === undefined) { blue = 0; }
729+
730+
return this.flash(duration, red, green, blue, true, callback);
731+
},
732+
733+
/**
734+
* Fades the Camera out to the given color over the duration specified.
735+
* This is an alias for Camera.fade that forces the fade to start, regardless of existing fades.
736+
*
737+
* @method Phaser.Cameras.Scene2D.Camera#fadeOut
738+
* @since 3.3.0
739+
*
740+
* @param {number} duration - The duration of the effect in milliseconds.
741+
* @param {function} [callback] - An optional callback to invoke when the fade completes. Will be sent one argument - a reference to this camera.
742+
* @param {number} [red=0] - The value to fade the red channel from. A value between 0 and 1.
743+
* @param {number} [green=0] - The value to fade the green channel from. A value between 0 and 1.
744+
* @param {number} [blue=0] - The value to fade the blue channel from. A value between 0 and 1.
745+
*
746+
* @return {Phaser.Cameras.Scene2D.Camera} This Camera instance.
747+
*/
748+
fadeOut: function (duration, callback, red, green, blue)
749+
{
750+
if (red === undefined) { red = 0; }
751+
if (green === undefined) { green = 0; }
752+
if (blue === undefined) { blue = 0; }
753+
754+
return this.fade(duration, red, green, blue, true, callback);
755+
},
756+
710757
/**
711758
* Fades the Camera to the given color over the duration specified.
712759
*
@@ -1370,7 +1417,7 @@ var Camera = new Class({
13701417

13711418
if (this._fadeCallback)
13721419
{
1373-
// Do this in case the callback flashes again (otherwise we'd overwrite the new callback)
1420+
// Do this in case the callback fades again (otherwise we'd overwrite the new callback)
13741421
var fadeCallback = this._fadeCallback;
13751422

13761423
this._fadeCallback = null;
@@ -1393,7 +1440,7 @@ var Camera = new Class({
13931440

13941441
if (this._shakeCallback)
13951442
{
1396-
// Do this in case the callback flashes again (otherwise we'd overwrite the new callback)
1443+
// Do this in case the callback shakes again (otherwise we'd overwrite the new callback)
13971444
var shakeCallback = this._shakeCallback;
13981445

13991446
this._shakeCallback = null;

0 commit comments

Comments
 (0)