Class Timer

java.lang.Object
react.Slot<Platform>
tripleplay.util.Timer
All Implemented Interfaces:
react.Reactor.RListener, react.SignalView.Listener<Platform>, react.ValueView.Listener<Platform>

public class Timer extends react.Slot<Platform>
Handles execution of actions after a specified delay. Create a Timer and connect it to the Platform.frame signal:

 public class MyGame extends SceneGame {
   public final Timer timer = new Timer();
   public MyGame (Platform plat) {
     plat.frame.connect(timer);
   }
 }
 
Then you can register actions to be performed at times in the future like so:

   // wherever
   game.timer.after(500, () -> {
      // this is run after 500ms
   });
 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    A handle on registered actions that can be used to cancel them.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a timer instance that can be used to schedule actions.
  • Method Summary

    Modifier and Type
    Method
    Description
    after(int millis, Runnable action)
    Executes the supplied action after the specified number of milliseconds have elapsed.
    atThenEvery(int initialMillis, int repeatMillis, Runnable action)
    Executes the supplied action starting initialMillis from now and every repeatMillis there after.
    every(int millis, Runnable action)
    Executes the supplied action starting millis from now and every millis thereafter.
    void
     

    Methods inherited from class react.Slot

    andThen, compose, filtered, onChange

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Timer

      public Timer()
      Creates a timer instance that can be used to schedule actions. Connect this timer to the frame signal to make it operable.
  • Method Details

    • after

      public Timer.Handle after(int millis, Runnable action)
      Executes the supplied action after the specified number of milliseconds have elapsed.
      Returns:
      a handle that can be used to cancel the execution of the action.
    • every

      public Timer.Handle every(int millis, Runnable action)
      Executes the supplied action starting millis from now and every millis thereafter.
      Returns:
      a handle that can be used to cancel the execution of the action.
    • atThenEvery

      public Timer.Handle atThenEvery(int initialMillis, int repeatMillis, Runnable action)
      Executes the supplied action starting initialMillis from now and every repeatMillis there after.
      Returns:
      a handle that can be used to cancel the execution of the action.
    • onEmit

      public void onEmit(Platform plat)