Scratch for Java

Sprite::addTimer()

Adds a new timer.

Examples

import org.openpatch.scratch.*;
 
public class SpriteAddTimer {
  public SpriteAddTimer() {
    Stage myStage = new Stage(600, 240);
    Sprite zeta = new Sprite("green", "assets/zeta_green_badge.png");
    zeta.addCostume("yellow", "assets/zeta_yellow_badge.png");
    zeta.addTimer("costumeChange");
    myStage.add(zeta);
    while (myStage.getTimer().forMillis(3000)) {
      if (zeta.getTimer("costumeChange").everyMillis(500)) {
        zeta.nextCostume();
      }
    }
    myStage.exit();
  }
 
  public static void main(String[] args) {
    new SpriteAddTimer();
  }
}
 

View on GitHub

Syntax

Java

.addTimer(name)

Scratch

add timer (name)

Parameters

Name Data Type Description
name String The name of the timer

Return

void

addTimer()