Class GameClock
java.lang.Object
org.openpatch.scratch.internal.GameClock
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidadvance()Before each step: game time moves on by one step.intframe(double realSeconds) A frame passed: how many game steps it gets.doublegetSpeed()booleanisPaused()doublemillis()Milliseconds of game time so far.voidpause()voidresume()voidsetSpeed(double speed) 1 is normal, 0.5 half as fast, 2 twice as fast; never below 0.voidstep()While paused: one step with the next frame.longsteps()Game steps so far: how often every run() was called.doubleGame time of the current step in seconds (0 between steps of a paused game).
-
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.
-