Skip to content

Instantly share code, notes, and snippets.

@tedigc
Last active September 15, 2017 01:20
Show Gist options
  • Select an option

  • Save tedigc/fe28616706025b00c6c540af4d03c827 to your computer and use it in GitHub Desktop.

Select an option

Save tedigc/fe28616706025b00c6c540af4d03c827 to your computer and use it in GitHub Desktop.
A simple Timer for libGDX projects
public class Timer {
private int delay;
private int elapsed;
private boolean running;
public Timer(int delay, boolean running) {
this.delay = delay;
this.running = running;
}
public boolean tick(float delta) {
if(running) {
elapsed += delta * 1000;
if(elapsed > delay) {
elapsed = elapsed - delay;
return true;
}
}
return false;
}
public void start() {
this.running = true;
}
public void stop() {
this.running = false;
}
public void reset() {
this.elapsed = 0;
}
public int getElapsed() {
return this.elapsed;
}
public void setElapsed(int elapsed) {
this.elapsed = elapsed;
}
public int getDelay() {
return delay;
}
public void setDelay(int delay) {
this.delay = delay;
}
public boolean isRunning() {
return running;
}
public float percent() {
return elapsed / (float) delay;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment