/// <summary> /// Apply the effect on the object /// </summary> /// <param name="gameTime">Time elpase since last update</param> public override void Apply(GameTime gameTime) { if (this.Control != null) { IFadeCapable fadeControl = (IFadeCapable)this.Control; //Apply fade effect fadeControl.Fade = (fadeControl.FadeIn) ? MathHelper.Min(fadeControl.Fade + ((float)gameTime.ElapsedGameTime.TotalSeconds * (int)this.Speed), this._to) : MathHelper.Max(fadeControl.Fade - ((float)gameTime.ElapsedGameTime.TotalSeconds * (int)this.Speed), this._from); if (this.Loop && fadeControl.Fade >= this._to)//if we loop and control fade is equal or better than the fade reach, set fade to start value { fadeControl.Fade = this._from; } } }
/// <summary> /// Create a new instance of a FadeEffect /// </summary> /// <param name="controle">Gui controle</param> /// <param name="speed">Speed of the Effect</param> /// <param name="from">From value of the Effect</param> /// <param name="to">To value of the Effect</param> /// <param name="loop">True if effect must loop</param> public FadeEffect(IFadeCapable controle, EffectSpeedEnum speed, float from, float to, bool loop = false) : base(controle, speed, loop) { this._from = from; this._to = to; }