Scratch for Java

Timer()

A timer counting game time in seconds, like Scratch's timer: it stops while the game is paused and runs faster at a higher game speed, so it agrees with everything else that happens in ticks. Every stage and sprite has one (getTimer()); make more as fields with new Timer().

private Timer shooting = new Timer();
 
public void run() {
  if (this.isKeyPressed(KeyCode.SPACE) && this.shooting.every(0.25)) {
    this.shoot();
  }
}

Syntax

Java

new Timer()
Timer()

Create Shareable URL

Select Sections