Hi!
So, I created a timer class. Here it is:
public class Timer implements Runnable {
public long timemillis;
public Thread runningthread;
public boolean done;
public Timer(float timemillis) {
this.timemillis = (long) timemillis;
done = false;
}
public void start() {
if (runningthread == null || !runningthread.isAlive()) {
runningthread = new Thread(this);
runningthread.start();
}
}
@Override
public void run() {
try {
Thread.sleep(timemillis);
} catch (InterruptedException e) {
e.printStackTrace();
}
done = true;
}
public void setTimer(long timemillis) {
this.timemillis = timemillis;
}
public boolean get() {
boolean tempdone = done;
done = false;
return tempdone;
}
}
I have an issue. When I use it, it works for a while. It runs, and I do get() to check if it is done, if so: start(). I do that a few times in the code, but all of the sudden, it stops working. It does not ever get done when I check through get(). What is happening?
Also, if you see a flaw in my code, do tell. I do not have any performance issues though (while running a lot of these never drops below 57fps!).