Documentation
The org.openpatch.scratch package contains classes that provide an API for creating Scratch-like projects in Java.
The documentation with many examples can be found at https://scratch4j.openpatch.org.
To create a scratch4j project, you will need to create a class that extends the Window class.
The Window class is the main class that represents the window of the project.
import org.openpatch.scratch.Window;
public class Game extends Window {
public Game() {
super(800, 600);
this.setStage(new MyStage());
}
}
The Stage class represents the stage of the project.
import org.openpatch.scratch.Stage;
class MyStage extends Stage {
public MyStage() {
this.add(new MySprite());
}
}
The Sprite class represents a sprite in the project.
import org.openpatch.scratch.Sprite;
class MySprite extends Sprite {
public MySprite() {
this.setCostume("cat_sitting", "cat.png");
}
public void run() {
this.ifOnEdgeBounce();
this.move(10);
}
}
This will create a window with a stage containing a sprite that moves 10 pixels every frame and bounces off the edges of the window.
