Module hanyaeger

Class Timer

java.lang.Object
com.github.hanyaeger.api.Timer
Direct Known Subclasses:
EntitySpawner, FadeInTimer

public abstract class Timer extends Object
The abstract superclass of all timers that are available for both YaegerScene and YaegerEntity. To add a Timer the YaegerEntity or YaegerScene should implement the interface TimerContainer, after which the method TimerContainer.setupTimers() should be implemented to add the newly created timers through the method TimerContainer.addTimer(Timer).

Extend this class and implement the method onAnimationUpdate(long).

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Timer(long intervalInMs)
    Create a new instance of Timer for the given interval in milliseconds.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Return the interval in ms that is being used by this Timer.
    protected void
    handle(long now)
    Handle an update.
    boolean
    State whether this Timer is currently active.
    boolean
    State whether this Timer has been marked as garbage.
    abstract void
    onAnimationUpdate(long timestamp)
    Implement this method, which will be called each animation update with the given interval.
    final void
    Pause the timer, so it will no longer update with each animation.
    void
    When this method is called, this Timer is set for removal.
    void
    Reset this Timer to start from the beginning again.
    final void
    Resume the timer, so it will start updating on each animation again.
    void
    setIntervalInMs(long intervalInMs)
    Set the interval in ms that should be used by this Timer.

    Methods inherited from class java.lang.Object

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

    • Timer

      protected Timer(long intervalInMs)
      Create a new instance of Timer for the given interval in milliseconds.
      Parameters:
      intervalInMs - the interval in milliseconds
  • Method Details

    • handle

      protected void handle(long now)
      Handle an update. This method is called on each interval as passed to the constructor of this Timer.
      Parameters:
      now - the current timestamp
    • pause

      public final void pause()
      Pause the timer, so it will no longer update with each animation.
    • resume

      public final void resume()
      Resume the timer, so it will start updating on each animation again.
    • remove

      public void remove()
      When this method is called, this Timer is set for removal. This will be done in the next Game World Update.
    • onAnimationUpdate

      public abstract void onAnimationUpdate(long timestamp)
      Implement this method, which will be called each animation update with the given interval.
      Parameters:
      timestamp - the timestamp of the current frame given in nanoseconds
    • isGarbage

      public boolean isGarbage()
      State whether this Timer has been marked as garbage.
      Returns:
      a boolean stating whether this Timer has been marked as garbage
    • isActive

      public boolean isActive()
      State whether this Timer is currently active. When a Timer is paused, it is no longer active.
      Returns:
      a boolean stating whether this Timer is active
    • getIntervalInMs

      public long getIntervalInMs()
      Return the interval in ms that is being used by this Timer.
      Returns:
      the interval in ms as a long
    • setIntervalInMs

      public void setIntervalInMs(long intervalInMs)
      Set the interval in ms that should be used by this Timer.
      Parameters:
      intervalInMs - the interval in ms as a long
    • reset

      public void reset()
      Reset this Timer to start from the beginning again.