Scratch for Java

Sprite::getTimer()

Returns the default timer or a timer with the given name. For more information about timer see the documentation for the Timer class.

Examples

import org.openpatch.scratch.Sprite;
import org.openpatch.scratch.Stage;
 
public class SpriteTimer {
  public SpriteTimer() {
    Stage myStage = new Stage(600, 240);
    Sprite timeMe = new Sprite("zeta", "assets/zeta_green_badge.png");
    timeMe.addCostume("gamma", "assets/gamma_purple_badge.png");
    timeMe.addTimer("identityChange");
    myStage.add(timeMe);
 
    while (myStage.getTimer().forMillis(6000)) {
      if (timeMe.getTimer("identityChange").everyMillis(1000)) {
        timeMe.nextCostume();
      }
    }
    myStage.exit();
  }
 
  public static void main(String[] args) {
    new SpriteTimer();
  }
}
 

View on GitHub

Syntax

Java

.getTimer()
.getTimer(name)

Scratch

(time [name v])

Parameters

Name Data Type Description
name String The name of the timer

Return

Timer

getTimer()