public class Timer
extends java.lang.Object
| Constructor and Description |
|---|
Timer(float interval,
float delay,
int repetitions,
java.lang.Runnable task)
Creates a new timer.
|
| Modifier and Type | Method and Description |
|---|---|
static Timer |
findTimer(int id)
Looks if there is an active timer with the provided id.
|
int |
getID()
Gets the ID of this timer.
|
float |
getInitialDelay()
Gets the remaining initial delay (seconds) of this timer.
|
float |
getInterval()
Gets the interval (seconds) of this timer.
|
int |
getRepetitions()
Gets how often the timer is supposed to trigger / repeat.
|
java.lang.Runnable |
getTask()
Gets the task which will be executed once the timer triggers, or null if no
task was set for this timer.
|
float |
getTick()
Used internally!
|
boolean |
isActive()
Gets whether or not this timer is currently active.
|
boolean |
isPaused()
Gets whether or not this timer is currently paused.
|
void |
kill()
Kills the timer and releases all resources which belong to this timer.
|
static boolean |
killTimer(int id)
Kills the timer which has the provided id.
|
void |
pause()
Pauses this timer.
|
void |
setInitialDelay(float delay)
Sets the initial delay for this timer.
|
void |
setInterval(float interval)
Sets the interval for this timer.
|
void |
setRepetitions(int repetitions)
Sets the amount of repetitions, i.e. how often the timer is supposed
to trigger / repeat.
|
void |
setTask(java.lang.Runnable task)
Sets a new task which will be executed once the timer triggers.
|
void |
setTick(float tick)
Used internally!
|
void |
start()
Starts the timer.
|
static boolean |
timerExists(int id)
Determines if an active timer with the provided id exists.
|
public Timer(float interval,
float delay,
int repetitions,
java.lang.Runnable task)
interval - the interval in seconds. Only applies to subsequent repetitions
(i.e. does not apply to first execution, in this case, set the initial delay instead).delay - the initial delay in seconds.repetitions - determines how often the timer should repeat. Use 0 if
the timer should only trigger once, or -1 if the timer should repeat
infinitely.task - a runnable which is executed when the timer triggers. It's allowed
to provide null and set the task at a later stage (see setTask(java.lang.Runnable)).public void start()
public void pause()
public void kill()
public boolean isActive()
isPaused()).public boolean isPaused()
isActive() into account.pause()public void setInterval(float interval)
interval - the new interval in seconds.public float getInterval()
public void setInitialDelay(float delay)
delay - the initial delay in seconds.public float getInitialDelay()
public void setRepetitions(int repetitions)
repetitions - the amount of repetitions.public int getRepetitions()
public java.lang.Runnable getTask()
public void setTask(java.lang.Runnable task)
task - the new Runnable task.public int getID()
public void setTick(float tick)
tick - time per frame.public float getTick()
public static Timer findTimer(int id)
id - the id of the timer.public static boolean killTimer(int id)
id - the timer id.public static boolean timerExists(int id)
id - the id of the timer.