namespace Otter {
///
/// Entity that acts as a screen flash. Best used when using the constructor that allows for
/// initial parameters be set:
///
/// Flash(Color.Red) { Alpha = 0.5, Blend = BlendMode.Add };
///
///
public class Flash : Entity {
#region Static Fields
///
/// The default life span for all created Flash Entities.
///
public static int DefaultLifeSpan = 60;
#endregion
#region Private Fields
Image imgFlash;
#endregion
#region Public Fields
///
/// The Color for the Flash.
///
public Color Color;
///
/// The initial alpha for the Flash.
///
public float Alpha = 1;
///
/// The final alpha for the Flash.
///
public float FinalAlpha = 0;
///
/// The BlendMode for the Flash.
///
public BlendMode Blend = BlendMode.Alpha;
#endregion
#region Constructors
///
/// Create a new Flash.
///
/// The Color of the Flash.
public Flash(Color color) : base(0, 0) {
Color = color;
}
#endregion
#region Public Methods
///
/// Added to the Scene.
///
public override void Added() {
base.Added();
if (LifeSpan == 0) {
LifeSpan = DefaultLifeSpan;
}
imgFlash = Image.CreateRectangle(Game.Instance.Width, Game.Instance.Height, Color);
imgFlash.Blend = Blend;
imgFlash.Scroll = 0;
imgFlash.CenterOriginZero();
if (Surface != null) {
imgFlash.Scale = 1 / Surface.CameraZoom;
}
else {
imgFlash.Scale = 1 / Game.Surface.CameraZoom;
}
SetGraphic(imgFlash);
}
///
/// Updated.
///
public override void Update() {
base.Update();
if (Surface != null) {
imgFlash.Scale = 1 / Surface.CameraZoom;
}
else {
imgFlash.Scale = 1 / Game.Surface.CameraZoom;
}
imgFlash.Alpha = Util.ScaleClamp(Timer, 0, LifeSpan, Alpha, FinalAlpha);
}
///
/// Removed from the Scene.
///
public override void Removed() {
base.Removed();
ClearGraphics();
}
#endregion
}
}