Class GameClock

java.lang.Object
org.openpatch.scratch.internal.GameClock

public final class GameClock extends Object
Game time: it stands still while the game is paused and runs slower or faster with the game speed. Each frame asks how many game steps (calls of every run()) it gets: at half speed every second frame gets one, at double speed every frame gets two, so slow motion slows down code that moves a fixed amount per frame as well as code that uses the frame time.

Timers, gliding and animations follow this clock; the window itself (transitions, the splash screen) keeps real time.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Before each step: game time moves on by one step.
    int
    frame(double realSeconds)
    A frame passed: how many game steps it gets.
    double
     
    boolean
     
    double
    Milliseconds of game time so far.
    void
     
    void
     
    void
    setSpeed(double speed)
    1 is normal, 0.5 half as fast, 2 twice as fast; never below 0.
    void
    While paused: one step with the next frame.
    long
    Game steps so far: how often every run() was called.
    double
    Game time of the current step in seconds (0 between steps of a paused game).

    Methods inherited from class Object

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

    • GameClock

      public GameClock()
  • Method Details

    • millis

      public double millis()
      Milliseconds of game time so far.
    • steps

      public long steps()
      Game steps so far: how often every run() was called.
    • stepSeconds

      public double stepSeconds()
      Game time of the current step in seconds (0 between steps of a paused game).
    • pause

      public void pause()
    • resume

      public void resume()
    • isPaused

      public boolean isPaused()
    • step

      public void step()
      While paused: one step with the next frame.
    • setSpeed

      public void setSpeed(double speed)
      1 is normal, 0.5 half as fast, 2 twice as fast; never below 0.
    • getSpeed

      public double getSpeed()
    • frame

      public int frame(double realSeconds)
      A frame passed: how many game steps it gets. stepSeconds() is the game time of each of them.
      Parameters:
      realSeconds - the real time since the last frame
    • advance

      public void advance()
      Before each step: game time moves on by one step.