APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.utils

public Class Timer

extends Object
Class Inheritance
Imports
com.badlogic.gdx.Application, .Files, .Gdx, .LifecycleListener

Executes tasks in the future on the main loop thread.
Author
Nathan Sweet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public abstract static class
Timer.Task

Runnable that can be scheduled on a Timer.

pack-priv static class
Timer.TimerThread

Manages a single thread for updating timers.

Field Summary

Modifier and TypeField and Description
pack-priv long
pack-priv final Array<Timer.Task>
pack-priv static Timer.TimerThread
pack-priv static final Object

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Cancels all tasks.

public synchronized void
delay(long delayMillis)

Adds the specified delay to all tasks.

public static Timer
instance()

Timer instance singleton for general application wide usage.

public synchronized boolean
isEmpty()

Returns true if the timer has no tasks in the queue.

public static Timer.Task
post(Timer.Task task)

Schedules a task on instance.

public Timer.Task
postTask(Timer.Task task)

Schedules a task to occur once as soon as possible, but not sooner than the start of the next frame.

public static Timer.Task
schedule(Timer.Task task, float delaySeconds)

Schedules a task on instance.

public static Timer.Task
schedule(Timer.Task task, float delaySeconds, float intervalSeconds)

Schedules a task on instance.

public static Timer.Task
schedule(Timer.Task task, float delaySeconds, float intervalSeconds, int repeatCount)

Schedules a task on instance.

public Timer.Task
scheduleTask(Timer.Task task, float delaySeconds)

Schedules a task to occur once after the specified delay.

public Timer.Task
scheduleTask(Timer.Task task, float delaySeconds, float intervalSeconds)

Schedules a task to occur once after the specified delay and then repeatedly at the specified interval until cancelled.

public Timer.Task
scheduleTask(Timer.Task task, float delaySeconds, float intervalSeconds, int
If negative, the task will repeat forever.
repeatCount
)

Schedules a task to occur once after the specified delay and then a number of additional times at the specified interval.

public void
start()

Starts the timer if it was stopped.

public void
stop()

Stops the timer if it was started.

pack-priv static Timer.TimerThread
pack-priv synchronized long
update(Timer.TimerThread thread, long timeMillis, long waitMillis)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

stopTimeMillisback to summary
pack-priv long stopTimeMillis
tasksback to summary
pack-priv final Array<Timer.Task> tasks
threadback to summary
pack-priv static Timer.TimerThread thread
threadLockback to summary
pack-priv static final Object threadLock

Constructor Detail

Timerback to summary
public Timer()

Method Detail

clearback to summary
public void clear()

Cancels all tasks.

delayback to summary
public synchronized void delay(long delayMillis)

Adds the specified delay to all tasks.

instanceback to summary
public static Timer instance()

Timer instance singleton for general application wide usage. Static methods on Timer make convenient use of this instance.

isEmptyback to summary
public synchronized boolean isEmpty()

Returns true if the timer has no tasks in the queue. Note that this can change at any time. Synchronize on the timer instance to prevent tasks being added, removed, or updated.

postback to summary
public static Timer.Task post(Timer.Task task)

Schedules a task on instance.

See Also
postTask(Task)
postTaskback to summary
public Timer.Task postTask(Timer.Task task)

Schedules a task to occur once as soon as possible, but not sooner than the start of the next frame.

scheduleback to summary
public static Timer.Task schedule(Timer.Task task, float delaySeconds)

Schedules a task on instance.

See Also
scheduleTask(Task, float)
scheduleback to summary
public static Timer.Task schedule(Timer.Task task, float delaySeconds, float intervalSeconds)

Schedules a task on instance.

See Also
scheduleTask(Task, float, float)
scheduleback to summary
public static Timer.Task schedule(Timer.Task task, float delaySeconds, float intervalSeconds, int repeatCount)

Schedules a task on instance.

See Also
scheduleTask(Task, float, float, int)
scheduleTaskback to summary
public Timer.Task scheduleTask(Timer.Task task, float delaySeconds)

Schedules a task to occur once after the specified delay.

scheduleTaskback to summary
public Timer.Task scheduleTask(Timer.Task task, float delaySeconds, float intervalSeconds)

Schedules a task to occur once after the specified delay and then repeatedly at the specified interval until cancelled.

scheduleTaskback to summary
public Timer.Task scheduleTask(Timer.Task task, float delaySeconds, float intervalSeconds, int repeatCount)

Schedules a task to occur once after the specified delay and then a number of additional times at the specified interval.

Parameters
repeatCount:int

If negative, the task will repeat forever.

startback to summary
public void start()

Starts the timer if it was stopped. Tasks are delayed by the time passed while stopped.

stopback to summary
public void stop()

Stops the timer if it was started. Tasks will not be executed while stopped.

threadback to summary
pack-priv static Timer.TimerThread thread()
updateback to summary
pack-priv synchronized long update(Timer.TimerThread thread, long timeMillis, long waitMillis)
com.badlogic.gdx.utils back to summary

public abstract Class Timer.Task

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable
Known Direct Subclasses
com.badlogic.gdx.scenes.scene2d.ui.TextField.KeyRepeatTask

Runnable that can be scheduled on a Timer.
Author
Nathan Sweet

Field Summary

Modifier and TypeField and Description
pack-priv final Application
pack-priv long
pack-priv long
pack-priv int
pack-priv volatile Timer

Constructor Summary

AccessConstructor and Description
public
Task()

Method Summary

Modifier and TypeMethod and Description
public void
cancel()

Cancels the task.

public synchronized long
getExecuteTimeMillis()

Returns the time in milliseconds when this task will be executed next.

public boolean
isScheduled()

Returns true if this task is scheduled to be executed in the future by a timer.

pack-priv synchronized void
public abstract void
run()

Redeclares java.lang.Runnable.run.

If this is the last time the task will be ran or the task is first cancelled, it may be scheduled again in this method.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

appback to summary
pack-priv final Application app
executeTimeMillisback to summary
pack-priv long executeTimeMillis
intervalMillisback to summary
pack-priv long intervalMillis
repeatCountback to summary
pack-priv int repeatCount
timerback to summary
pack-priv volatile Timer timer

Constructor Detail

Taskback to summary
public Task()

Method Detail

cancelback to summary
public void cancel()

Cancels the task. It will not be executed until it is scheduled again. This method can be called at any time.

getExecuteTimeMillisback to summary
public synchronized long getExecuteTimeMillis()

Returns the time in milliseconds when this task will be executed next.

isScheduledback to summary
public boolean isScheduled()

Returns true if this task is scheduled to be executed in the future by a timer. The execution time may be reached at any time after calling this method, which may change the scheduled state. To prevent the scheduled state from changing, synchronize on this task object, eg:

synchronized (task) {
	if (!task.isScheduled()) { ... }
}
resetback to summary
pack-priv synchronized void reset()
runback to summary
public abstract void run()

Redeclares java.lang.Runnable.run.

If this is the last time the task will be ran or the task is first cancelled, it may be scheduled again in this method.

com.badlogic.gdx.utils back to summary

pack-priv Class Timer.TimerThread

extends Object
implements Runnable, LifecycleListener
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.LifecycleListener, java.lang.Runnable

Manages a single thread for updating timers. Uses libgdx application events to pause, resume, and dispose the thread.
Author
Nathan Sweet

Field Summary

Modifier and TypeField and Description
pack-priv final Application
pack-priv final Files
pack-priv Timer
pack-priv final Array<Timer>
pack-priv long
pack-priv final Array<Timer.Task>
private final Runnable
pack-priv final Array<Timer.Task>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv void
public void
dispose()

Implements com.badlogic.gdx.LifecycleListener.dispose.

Called when the Application is about to be disposed

public void
pause()

Implements com.badlogic.gdx.LifecycleListener.pause.

Called when the Application is about to pause

pack-priv void
public void
resume()

Implements com.badlogic.gdx.LifecycleListener.resume.

Called when the Application is about to be resumed

public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

appback to summary
pack-priv final Application app
filesback to summary
pack-priv final Files files
instanceback to summary
pack-priv Timer instance
instancesback to summary
pack-priv final Array<Timer> instances
pauseTimeMillisback to summary
pack-priv long pauseTimeMillis
postedTasksback to summary
pack-priv final Array<Timer.Task> postedTasks
runPostedTasksback to summary
private final Runnable runPostedTasks
runTasksback to summary
pack-priv final Array<Timer.Task> runTasks

Constructor Detail

TimerThreadback to summary
public TimerThread()

Method Detail

addPostedTaskback to summary
pack-priv void addPostedTask(Timer.Task task)
disposeback to summary
public void dispose()

Implements com.badlogic.gdx.LifecycleListener.dispose.

Doc from com.badlogic.gdx.LifecycleListener.dispose.

Called when the Application is about to be disposed

pauseback to summary
public void pause()

Implements com.badlogic.gdx.LifecycleListener.pause.

Doc from com.badlogic.gdx.LifecycleListener.pause.

Called when the Application is about to pause

removePostedTaskback to summary
pack-priv void removePostedTask(Timer.Task task)
resumeback to summary
public void resume()

Implements com.badlogic.gdx.LifecycleListener.resume.

Doc from com.badlogic.gdx.LifecycleListener.resume.

Called when the Application is about to be resumed

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

runPostedTasksback to summary
pack-priv void runPostedTasks()