/// <summary> /// Creates a new Interpolator. /// </summary> /// <param name="start">The starting value.</param> /// <param name="end">The ending value.</param> /// <param name="length">The length of time, in seconds, to perform the interpolation.</param> /// <param name="scale">A method to perform</param> /// <param name="step">An optional callback to invoke when the Interpolator is updated.</param> /// <param name="completed">An optional callback to invoke when the Interpolator completes.</param> /// <returns>The Interpolator instance.</returns> public static Interpolator Create( float start, float end, float length, InterpolatorScaleDelegate scale, InterpolatorEaseDirection direction, Action <Interpolator> step, Action <Interpolator> completed) { if (length <= 0f) { throw new ArgumentException("length must be greater than zero"); } if (scale == null) { throw new ArgumentNullException("scale"); } var i = Interpolators.New(); i.Start = start; i.End = end; i._range = end - start; i._step = step; i._completed = completed; i._scale = scale; i._speed = 1f / length; i._direction = direction; return(i); }
/// <summary> /// Creates a new Interpolator. /// </summary> /// <param name="start">The starting value.</param> /// <param name="end">The ending value.</param> /// <param name="length">The length of time, in seconds, to perform the interpolation.</param> /// <param name="scale">A delegate that handles converting the interpolator's progress to a value.</param> /// <param name="step">An optional callback to invoke when the Interpolator is updated.</param> /// <param name="completed">An optional callback to invoke when the Interpolator completes.</param> /// <returns>The Interpolator instance.</returns> public Interpolator Create( float start, float end, float length, InterpolatorScaleDelegate scale, Action <Interpolator> step, Action <Interpolator> completed) { lock (interpolators) { Interpolator i = interpolators.New(); i.Reset(start, end, length, scale, step, completed); return(i); } }
/// <summary> /// Creates a new Interpolator. /// </summary> /// <param name="start">The starting value.</param> /// <param name="end">The ending value.</param> /// <param name="length">The length of time, in seconds, to perform the interpolation.</param> /// <param name="scale">A delegate that handles converting the interpolator's progress to a value.</param> /// <param name="step">An optional callback to invoke when the Interpolator is updated.</param> /// <param name="completed">An optional callback to invoke when the Interpolator completes.</param> /// <returns>The Interpolator instance.</returns> public Interpolator Create( float start, float end, float length, InterpolatorScaleDelegate scale, Action<Interpolator> step, Action<Interpolator> completed) { lock (interpolators) { Interpolator i = interpolators.New(); i.Reset(start, end, length, scale, step, completed); return i; } }
/// <summary> /// Updates the Interpolator. /// </summary> /// <param name="frameTime"></param> public void Update(float frameTime) { if (!_valid) { return; } // update the progress, clamping at 1f _progress = Math.Min(_progress + _speed * frameTime, 1f); // get the scaled progress and use that to generate the value float scaledProgress = _scale(_progress); _value = _start + _range * scaledProgress; // invoke the step callback if (_step != null) { _step(this); } // if the progress is 1... if (_progress == 1f) { // the interpolator is done _valid = false; // invoke the completed callback if (_completed != null) { _completed(this); } Tag = null; _scale = null; _step = null; _completed = null; } }
/// <summary> /// Updates the Interpolator. /// </summary> /// <param name="gameTime"></param> public void Update(GameTime gameTime) { if (!valid) { return; } // update the progress, clamping at 1f progress = Math.Min(progress + speed * (float)gameTime.ElapsedGameTime.TotalSeconds, 1f); // get the scaled progress and use that to generate the value float scaledProgress = scale(progress); value = start + range * scaledProgress; // invoke the step callback if (step != null) { step(this); } // if the progress is 1... if (progress == 1f) { // the interpolator is done valid = false; // invoke the completed callback if (completed != null) { completed(this); } Tag = null; scale = null; step = null; completed = null; } }
internal void Reset(float s, float e, float l, InterpolatorScaleDelegate scaleFunc, Action <Interpolator> stepFunc, Action <Interpolator> completedFunc) { if (l <= 0f) { throw new ArgumentException("length must be greater than zero"); } if (scaleFunc == null) { throw new ArgumentNullException("scaleFunc"); } valid = true; progress = 0f; start = s; end = e; range = e - s; speed = 1f / l; scale = scaleFunc; step = stepFunc; completed = completedFunc; }
/// <summary> /// Creates a new Interpolator. /// </summary> /// <param name="start">The starting value.</param> /// <param name="end">The ending value.</param> /// <param name="length">The length of time, in seconds, to perform the interpolation.</param> /// <param name="scale">A method to perform</param> /// <param name="step">An optional callback to invoke when the Interpolator is updated.</param> /// <param name="completed">An optional callback to invoke when the Interpolator completes.</param> /// <returns>The Interpolator instance.</returns> public static Interpolator Create( float start, float end, float length, InterpolatorScaleDelegate scale, Action<Interpolator> step, Action<Interpolator> completed) { if (length <= 0f) throw new ArgumentException("length must be greater than zero"); if (scale == null) throw new ArgumentNullException("scale"); var i = Interpolators.New(); i.Start = start; i.End = end; i._range = end - start; i._step = step; i._completed = completed; i._scale = scale; i._speed = 1f / length; return i; }
/// <summary> /// Creates a new Interpolator. /// </summary> /// <param name="startValue">The starting value.</param> /// <param name="endValue">The ending value.</param> /// <param name="interpolationLength">The amount of time, in seconds, for the interpolation to occur.</param> /// <param name="scale">A custom delegate to use for scaling the Interpolator's value.</param> /// <param name="step">An optional delegate to invoke each update.</param> /// <param name="completed">An optional delegate to invoke upon completion.</param> public Interpolator(float startValue, float endValue, float interpolationLength, InterpolatorScaleDelegate scale, Action<Interpolator> step, Action<Interpolator> completed) { Reset(startValue, endValue, interpolationLength, scale, step, completed); }
internal void Reset(float s, float e, float l, InterpolatorScaleDelegate scaleFunc, Action<Interpolator> stepFunc, Action<Interpolator> completedFunc) { if (l <= 0f) throw new ArgumentException("length must be greater than zero"); if (scaleFunc == null) throw new ArgumentNullException("scaleFunc"); valid = true; progress = 0f; start = s; end = e; range = e - s; speed = 1f / l; scale = scaleFunc; step = stepFunc; completed = completedFunc; }
/// <summary> /// Updates the Interpolator. /// </summary> /// <param name="gameTime"></param> public void Update(GameTime gameTime) { if (!valid) return; // update the progress, clamping at 1f progress = Math.Min(progress + speed * (float)gameTime.ElapsedGameTime.TotalSeconds, 1f); // get the scaled progress and use that to generate the value float scaledProgress = scale(progress); value = start + range * scaledProgress; // invoke the step callback if (step != null) step(this); // if the progress is 1... if (progress == 1f) { // the interpolator is done valid = false; // invoke the completed callback if (completed != null) completed(this); Tag = null; scale = null; step = null; completed = null; } }
/// <summary> /// Creates a new Interpolator. /// </summary> /// <param name="startValue">The starting value.</param> /// <param name="endValue">The ending value.</param> /// <param name="interpolationLength">The amount of time, in seconds, for the interpolation to occur.</param> /// <param name="scale">A custom delegate to use for scaling the Interpolator's value.</param> /// <param name="step">An optional delegate to invoke each update.</param> /// <param name="completed">An optional delegate to invoke upon completion.</param> public Interpolator(float startValue, float endValue, float interpolationLength, InterpolatorScaleDelegate scale, Action <Interpolator> step, Action <Interpolator> completed) { Reset(startValue, endValue, interpolationLength, scale, step, completed); }
/// <summary> /// Initializes a new instance of the <see cref="Interpolator" /> class. /// </summary> /// <param name="startValue"> /// The value at which the interpolator starts. /// </param> /// <param name="endValue">The value at which the interpolator ends.</param> /// <param name="length">The length in seconds of the interpolation.</param> /// <param name="step">The action to perform on each step.</param> /// <param name="completed"> /// The action to perform when the interpolator completes. /// </param> /// <param name="scale">The kind of interpolator scale to use.</param> public Interpolator(float startValue, float endValue, float length, Action<Interpolator> step, Action<Interpolator> completed, InterpolatorScaleDelegate scale) { Reset(startValue, endValue, length, step, completed, scale); }
/// <summary> /// Initializes a new instance of the <see cref="Interpolator" /> class. /// </summary> /// <param name="startValue"> /// The value at which the interpolator starts. /// </param> /// <param name="endValue">The value at which the interpolator ends.</param> /// <param name="length">The length in seconds of the interpolation.</param> /// <param name="step">The action to perform on each step.</param> /// <param name="scale">The kind of interpolator scale to use.</param> public Interpolator(float startValue, float endValue, float length, Action<Interpolator> step, InterpolatorScaleDelegate scale) : this(startValue, endValue, length, step, null, scale) { }
/// <summary> /// Resets the values of this interpolator. /// </summary> /// <param name="startValue"> /// The value at which the interpolator starts. /// </param> /// <param name="endValue">The value at which the interpolator ends.</param> /// <param name="length">The length in seconds of the interpolation.</param> /// <param name="step">The action to perform on each step.</param> /// <param name="completed"> /// The action to perform when the interpolator completes. /// </param> /// <param name="scale">The kind of interpolator scale to use.</param> internal void Reset(float startValue, float endValue, float length, Action<Interpolator> step, Action<Interpolator> completed, InterpolatorScaleDelegate scale) { if (length <= 0) { throw new ArgumentException("'length' must be greater than zero.", "length"); } if (scale == null) { throw new ArgumentNullException("'scale' cannot be null.", "scale"); } Enabled = true; Progress = 0; Value = Start; Start = startValue; End = endValue; Length = length; Completed = completed; Step = step; Scale = scale; }