Collection of useful utilities for Java games and apps. A lot of interesting utilities that could maybe still find some use if you work with Java...
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mightyutils/src/mightypork/utils/math/timing/TimedTask.java

52 lines
810 B

package mightypork.utils.math.timing;
import mightypork.utils.interfaces.Updateable;
import mightypork.utils.math.animation.NumAnimated;
/**
* Delayed runnable controlled by delta timing.
*
* @author Ondřej Hruška (MightyPork)
*/
public abstract class TimedTask implements Runnable, Updateable {
private final NumAnimated timer = new NumAnimated(0);
private boolean running = false;
@Override
public void update(double delta)
{
if (running) {
timer.update(delta);
if (timer.isFinished()) {
running = false;
run();
}
}
}
public boolean isRunning()
{
return !timer.isFinished();
}
public void start(double seconds)
{
timer.reset();
timer.animate(1, seconds);
running = true;
}
public void stop()
{
running = false;
timer.reset();
}
}