/// <summary> /// Starts the animation /// After start you can get the current value in <see cref="AnimationDrop.GetCurrentValue" /> method /// </summary> /// <param name="startVal">Starting AnimationDropData of the element</param> public void Start(AnimationDropData startVal) { if (this.IsWorking) { this.Stop(); } this.startValue = startVal; this.startTime = Game.Time; }
/// <summary> /// Decreases the Height until it reaches 0 /// </summary> /// <param name="curTime">Current Time (seconds)</param> /// <param name="val">AnimationDropData</param> /// <param name="dur">Duration</param> /// <returns>New calculated AnimationDropData</returns> private AnimationDropData VerticalDecrease(double curTime, AnimationDropData val, double dur) { var rec = val.Rectangle; Color col = val.Color; rec.Height = val.Rectangle.Height - (int)this.Linear(curTime, 0, val.Rectangle.Height, dur) - 1; col.A = (byte)(this.InverseLinear(curTime, val.Color.A, dur)); var data = new AnimationDropData(rec, col); return(data); }
/// <summary> /// Increases the Height from 0 to specified height /// </summary> /// <param name="curTime">Current Time (seconds)</param> /// <param name="val">AnimationDropData</param> /// <param name="dur">Duration</param> /// <returns>New calculated AnimationDropData</returns> private AnimationDropData VerticalIncrease(double curTime, AnimationDropData val, double dur) { Rectangle rec = val.Rectangle; Color col = val.Color; rec.Height = (int)this.Linear(curTime, 0, val.Rectangle.Height, dur) + 1; col = new ColorBGRA(val.Color.B, val.Color.G, val.Color.R, (byte)this.Linear(curTime, val.Color.A, 255 - val.Color.A, dur)); AnimationDropData data = new AnimationDropData(rec, col); return(data); }
/// <summary> /// Decreases the Width until it reaches 0 /// </summary> /// <param name="curTime">Current Time (seconds)</param> /// <param name="val">AnimationDropData</param> /// <param name="dur">Duration</param> /// <returns>New calculated AnimationDropData</returns> private AnimationDropData HorizontalDecrease(double curTime, AnimationDropData val, double dur) { Rectangle rec = val.Rectangle; Color col = val.Color; rec.Width = val.Rectangle.Width - (int)this.Linear(curTime, 0, val.Rectangle.Width, dur) - 1; col.A = (byte)(this.InverseLinear(curTime, val.Color.A, dur)); AnimationDropData data = new AnimationDropData(rec, col); return(data); }
/// <summary> /// Increases the Width from 0 to specified width /// </summary> /// <param name="curTime">Current Time (seconds)</param> /// <param name="val">AnimationDropData</param> /// <param name="dur">Duration</param> /// <returns>New calculated AnimationDropData</returns> private AnimationDropData HorizontalIncrease(double curTime, AnimationDropData val, double dur) { var rec = val.Rectangle; Color col = val.Color; rec.Width = (int)this.Linear(curTime, 0, val.Rectangle.Width, dur) + 1; col = new ColorBGRA( val.Color.B, val.Color.G, val.Color.R, (byte)this.Linear(curTime, val.Color.A, 255 - val.Color.A, dur)); var data = new AnimationDropData(rec, col); return(data); }
/// <summary> /// Calculates the value of the specified mode /// </summary> /// <param name="curTime">Current Time (seconds)</param> /// <param name="startVal">Start Value</param> /// <param name="dur">Duration of the animation</param> /// <returns>Returns the calculated value of the specified mode</returns> private AnimationDropData Calculate(double curTime, AnimationDropData startVal, double dur) { switch (this.mode) { case Mode.VerticalDecrease: this.endValue = this.VerticalDecrease(curTime, startVal, dur); break; case Mode.VerticalIncrease: this.endValue = this.VerticalIncrease(curTime, startVal, dur); break; case Mode.HorizontalDecrease: this.endValue = this.HorizontalDecrease(curTime, startVal, dur); break; case Mode.HorizontalIncrease: this.endValue = this.HorizontalIncrease(curTime, startVal, dur); break; } return(this.endValue ?? this.startValue); }
/// <summary> /// Initializes a new instance of the <see cref="AnimationDrop" /> class. /// </summary> /// <param name="mode">Selected mode for calculation</param> /// <param name="duration">Selected duration for the defined animation</param> /// <param name="defaultAnimDropData">Default AnimationDropData of the element</param> public AnimationDrop(Mode mode, float duration, AnimationDropData defaultAnimDropData) : base(duration) { this.mode = mode; this.startValue = defaultAnimDropData; }