Package org.openpatch.scratch


package org.openpatch.scratch
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.
  • Class
    Description
    Contains virtual key code constants for keyboard input handling.
    The MouseCode enum represents the different mouse buttons that can be used.
    The Operators class provides a collection of static methods for performing various mathematical operations.
    The RotationStyle enum represents the different rotation styles that a sprite can have in Scratch.
    The `Sprite` class represents a graphical object that can be displayed on a stage.
    The Stage class represents a stage where various elements such as sprites, texts, pens, and backdrops can be added and manipulated.
    The Window class represents a singleton window for the application.