Fixed issue with looping animation pausing during transition, created new issue because of KeyFrame PathMethods (eases)

This commit is contained in:
Tinglyyy
2026-02-08 22:31:29 +01:00
parent a268926d0b
commit e61dbfa531
5 changed files with 134 additions and 35 deletions

View File

@@ -19,23 +19,34 @@ public interface AnimatedComponent {
default void play(double speed, boolean loop) {
AtomicInteger ticksPassed = new AtomicInteger();
// cloning the animation path to not mess with the original,
// if an extra frame is to be added because loop is set to true
AnimationPath playedPath = this.getAnimationPath().clone();
if(loop)
playedPath.add(playedPath.getNext());
this.setCurrentRun(new Timer(0, e -> {
if (!playedPath.anyMore()) {
System.out.println("called");
if(ticksPassed.get() * speed / (100) < 1) {
ticksPassed.addAndGet(this.getAnimationPath().getInbetweens());
return;
}
KeyFrame next = this.getAnimationPath().getNext();
if(next == null) {
if(loop)
this.getAnimationPath().reset();
if (loop)
playedPath.reset();
else
((Timer) e.getSource()).stop();
return;
}
if(ticksPassed.get() * speed / (100) < 1) {
ticksPassed.addAndGet(playedPath.getInbetweens());
return;
}
System.out.println("still executing");
KeyFrame next = playedPath.getNext();
this.setBounds(next.position().x, next.position().y, next.width(), next.height());
ticksPassed.set(0);