Further work on fixing keyframe path methods (still not working), and declared "momentum" functionality for replaying AnimationPaths through AnimatedComponents (not implemented yet). Added Javadocs.

This commit is contained in:
Tinglyyy
2026-02-09 22:15:18 +01:00
parent e61dbfa531
commit 59d72537b9
3 changed files with 166 additions and 24 deletions

View File

@@ -7,6 +7,8 @@ package org.openautonomousconnection.oacswing.animated;
import javax.swing.*;
import java.util.concurrent.atomic.AtomicInteger;
// TODO: Implement pause functionality
// (preferably not interfering with play() always reliably playing the animation from the start; aka define it as "setPaused(bool)" or "pause()" and "unpause()")
public interface AnimatedComponent {
void setCurrentRun(Timer timer);
Timer getCurrentRun();
@@ -16,7 +18,15 @@ public interface AnimatedComponent {
void setBounds(int x, int y, int width, int height);
default void play(double speed, boolean loop) {
//TODO: implement momentum
/**
* Plays this object's animation path
* @param speed how fast the animation should play
* @param loop if should the animation should loop
* @param momentum basically how far an object "shoots off" from a specified keyframe when stopping at proportional speed
* (linear keyframes are excluded from this)
*/
default void play(double speed, boolean loop, double momentum) {
AtomicInteger ticksPassed = new AtomicInteger();
// cloning the animation path to not mess with the original,
@@ -29,8 +39,6 @@ public interface AnimatedComponent {
this.setCurrentRun(new Timer(0, e -> {
if (!playedPath.anyMore()) {
System.out.println("called");
if (loop)
playedPath.reset();
else
@@ -43,8 +51,6 @@ public interface AnimatedComponent {
return;
}
System.out.println("still executing");
KeyFrame next = playedPath.getNext();
this.setBounds(next.position().x, next.position().y, next.width(), next.height());
@@ -55,14 +61,33 @@ public interface AnimatedComponent {
this.getCurrentRun().start();
}
/**
* Plays this object's animation path
* @param speed how fast the animation should play
* @param loop if should the animation should loop
*/
default void play(double speed, boolean loop) {
this.play(speed, loop, 0);
}
/**
* Plays this object's animation path
* @param speed how fast the animation should play
*/
default void play(double speed) {
this.play(speed, false);
}
/**
* Plays this object's animation path
*/
default void play() {
this.play(1, false);
}
/**
* Stops and resets replay of this object's animation path
*/
default void stop() {
if(this.getCurrentRun() != null)
if(this.getCurrentRun().isRunning())