Scratch for Java

Sprite::run()

This method is called every frame. This method has the some effect like a for ever loop in a when green flag clicked block.

Examples

import org.openpatch.scratch.*;
 
public class SpriteRun {
 
  public SpriteRun() {
    Stage myStage = new Stage(600, 240);
    myStage.add(new Zeta());
    while (myStage.getTimer().forMillis(3000)) {
      // wait for 3000 millis
    }
    myStage.exit();
  }
 
  public static void main(String[] args) {
    new SpriteRun();
  }
}
 
class Zeta extends Sprite {
 
  public Zeta() {
    super("green", "assets/zeta_green_badge.png");
  }
 
  @Override
  public void run() {
    this.move(5);
  }
}
 

View on GitHub

Syntax

Java

void run()

Scratch

run :: hat

Return

void

run()