Last active
September 15, 2017 01:20
-
-
Save tedigc/fe28616706025b00c6c540af4d03c827 to your computer and use it in GitHub Desktop.
A simple Timer for libGDX projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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