From 6861a93a8257cdf41ef4c035180c98a77849afad Mon Sep 17 00:00:00 2001 From: kainage Date: Thu, 17 Sep 2020 21:39:14 -0700 Subject: [PATCH] Allow setting alpha for 2D camera flash effect * Allow the overriding of `this.alpha` value for the camera flash effect --- src/cameras/2d/effects/Flash.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/cameras/2d/effects/Flash.js b/src/cameras/2d/effects/Flash.js index 2d9898901..07caf8f7f 100644 --- a/src/cameras/2d/effects/Flash.js +++ b/src/cameras/2d/effects/Flash.js @@ -104,10 +104,9 @@ var Flash = new Class({ * * @name Phaser.Cameras.Scene2D.Effects.Flash#alpha * @type {number} - * @private * @since 3.5.0 */ - this.alpha = 0; + this.alpha = 1; /** * If this effect is running this holds the current percentage of the progress, a value between 0 and 1. @@ -128,6 +127,17 @@ var Flash = new Class({ */ this._elapsed = 0; + /** + * This is an internal copy of the initial value of `this.alpha`, used to calculate the current alpha value of the fade effect. + * + * @name Phaser.Cameras.Scene2D.Effects.Flash#_alpha + * @type {number} + * @private + * @readonly + * @since 3.50.0 + */ + this._alpha; + /** * This callback is invoked every frame for the duration of the effect. * @@ -191,8 +201,8 @@ var Flash = new Class({ this.red = red; this.green = green; this.blue = blue; - this.alpha = 1; + this._alpha = this.alpha; this._elapsed = 0; this._onUpdate = callback; @@ -230,7 +240,7 @@ var Flash = new Class({ if (this._elapsed < this.duration) { - this.alpha = 1 - this.progress; + this.alpha = this._alpha * (1 - this.progress); } else { @@ -304,6 +314,7 @@ var Flash = new Class({ */ effectComplete: function () { + this._alpha = this.alpha this._onUpdate = null; this._onUpdateScope = null;