Class Timer


  • public class Timer
    extends java.lang.Object
    Executes tasks in the future on the main loop thread.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Timer.Task
      Runnable that can be scheduled on a Timer.
    • Constructor Summary

      Constructors 
      Constructor Description
      Timer()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Cancels all tasks.
      void delay​(long delayMillis)
      Adds the specified delay to all tasks.
      static Timer instance()
      Timer instance singleton for general application wide usage.
      boolean isEmpty()
      Returns true if the timer has no tasks in the queue.
      static Timer.Task post​(Timer.Task task)
      Schedules a task on instance().
      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.
      static Timer.Task schedule​(Timer.Task task, float delaySeconds)
      Schedules a task on instance().
      static Timer.Task schedule​(Timer.Task task, float delaySeconds, float intervalSeconds)
      Schedules a task on instance().
      static Timer.Task schedule​(Timer.Task task, float delaySeconds, float intervalSeconds, int repeatCount)
      Schedules a task on instance().
      Timer.Task scheduleTask​(Timer.Task task, float delaySeconds)
      Schedules a task to occur once after the specified delay.
      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.
      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.
      void start()
      Starts the timer if it was stopped.
      void stop()
      Stops the timer, tasks will not be executed and time that passes will not be applied to the task delays.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Timer

        public Timer()
    • Method Detail

      • instance

        public static Timer instance()
        Timer instance singleton for general application wide usage. Static methods on Timer make convenient use of this instance.
      • postTask

        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.
      • scheduleTask

        public Timer.Task scheduleTask​(Timer.Task task,
                                       float delaySeconds)
        Schedules a task to occur once after the specified delay.
      • scheduleTask

        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.
      • scheduleTask

        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 - If negative, the task will repeat forever.
      • stop

        public void stop()
        Stops the timer, tasks will not be executed and time that passes will not be applied to the task delays.
      • start

        public void start()
        Starts the timer if it was stopped.
      • clear

        public void clear()
        Cancels all tasks.
      • isEmpty

        public 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.
      • delay

        public void delay​(long delayMillis)
        Adds the specified delay to all tasks.