diff --git a/src/schule/ngb/zm/anim/Animations.java b/src/schule/ngb/zm/anim/Animations.java index c4e7b96..d9f63a2 100644 --- a/src/schule/ngb/zm/anim/Animations.java +++ b/src/schule/ngb/zm/anim/Animations.java @@ -3,6 +3,7 @@ package schule.ngb.zm.anim; import schule.ngb.zm.Color; import schule.ngb.zm.Constants; import schule.ngb.zm.Vector; +import schule.ngb.zm.tasks.FrameSynchronizedTask; import schule.ngb.zm.tasks.TaskRunner; import schule.ngb.zm.util.Log; import schule.ngb.zm.util.Validator; @@ -143,7 +144,7 @@ public class Animations { } public static final Future animate( T target, int runtime, DoubleUnaryOperator easing, DoubleConsumer stepper ) { - final long starttime = System.currentTimeMillis(); + /*final long starttime = System.currentTimeMillis(); return TaskRunner.run(() -> { double t = 0.0; do { @@ -156,6 +157,22 @@ public class Animations { t = (double) (System.currentTimeMillis() - starttime) / (double) runtime; } while( t < 1.0 ); stepper.accept(easing.applyAsDouble(1.0)); + }, target);*/ + return TaskRunner.run(new FrameSynchronizedTask() { + double t = 0.0; + final long starttime = System.currentTimeMillis(); + @Override + public void update( double delta ) { + // One animation step for t in [0,1] + stepper.accept(easing.applyAsDouble(t)); + t = (double) (System.currentTimeMillis() - starttime) / (double) runtime; + running = (t <= 1.0); + } + + @Override + protected void finish() { + stepper.accept(easing.applyAsDouble(1.0)); + } }, target); } @@ -168,7 +185,7 @@ public class Animations { ); } - public static Future animate( Animation animation ) { + /*public static Future animate( Animation animation ) { animation.start(); return null; } @@ -176,7 +193,7 @@ public class Animations { public static Future animate( Animation animation, DoubleUnaryOperator easing ) { animation.start(easing); return null; - } + }*/ public static final Log LOG = Log.getLogger(Animations.class);