Scratch for Java

Sprite()

A sprite: an object on the stage with costumes, a position and a direction, and code that runs every tick in run(), like a sprite and its scripts in Scratch.

public class Cat extends Sprite {
  public Cat() {
    this.addCostume("cat", "assets/cat.png");
  }
 
  public void run() {
    this.move(2);
    this.ifOnEdgeBounce();
  }
}

Positions are Scratch's: (0, 0) is the centre of the stage, x grows to the right and y upwards. Directions are Scratch's too: 0 points up, 90 to the right (the start direction), 180 down, 270 to the left. Everything a sprite does happens in ticks of 1/60 s of game time, so move(5) in run() moves 5 steps per tick on every computer.

Syntax

Java

new Sprite()
new Sprite(name, imagePath)

Static Fields

Name Type Description
DIRECTION_UP double Direction pointing up (0 degrees).
DIRECTION_RIGHT double Direction pointing right (90 degrees), where a new sprite points.
DIRECTION_DOWN double Direction pointing down (180 degrees).
DIRECTION_LEFT double Direction pointing left (270 degrees).
Sprite()

Create Shareable URL

Select Sections