public void MoveRandom() { if (animator != null) { return; } float duration = 1; duration = durations[randomizer.Next(0, durations.Length)]; OOEInterpolation interpolation = interpolations[randomizer.Next(0, interpolations.Length)]; animator = new OOEValueAnimator().Duration(duration).From(0).To(1).Interpolation(interpolation); previousLocation = frame.origin; destination.x = ((float)randomizer.NextDouble() * playgroundSize.width) - frame.origin.x; destination.y = ((float)randomizer.NextDouble() * playgroundSize.height) - frame.origin.y; animator.OnValueChange = (value) => { frame.origin.x = previousLocation.x + (destination.x * value); frame.origin.y = previousLocation.y + (destination.y * value); }; animator.OnFinish = () => { animator.Dispose(); animator = null; MoveRandom(); }; animator.Start(); }
public override void FixedUpdate() { if (this.State == OOEAnimationState.running) { Console.WriteLine("OOEValueAnimator.FixedUpdate is running."); Console.WriteLine("Animator State :" + State); Console.WriteLine("Is Paused : " + IsPaused); OOEInterpolation interpolation = this.interpolator; if (interpolation == null) { interpolation = OOEInterpolation.linear; } currentTime += timePerFrame; if (currentTime >= totalTime) { currentTime = totalTime; } // Console.WriteLine("OOEValueAnimator.currentTime = " + currentTime); if (OnValueChange != null) { float value = interpolation.InterpolatedValueOf(currentTime, totalTime, startValue: fromValue, endValue: toValue); OnValueChange(value); } if (currentTime == totalTime) { Pause(); if (OnFinish != null) { OnFinish(); } } } }
public OOEValueAnimator Interpolation(OOEInterpolation interpolator) { this.interpolator = interpolator; return(this); }