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.
 
  *
 public class Game extends Window {
      public Game() {
          super(800, 600);
          this.setStage(new MyStage());
      }
 }
 
 
The Stage class represents the stage of the project.
 
  *
 class MyStage extends Stage {
      public MyStage() {
          this.add(new MySprite());
      }
 }
 
 
The Sprite class represents a sprite in the project.
 
  *
 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.

Running the examples here

Nearly every method on the following pages comes with an example you can start and change without leaving the page. Those run in your browser rather than on your own computer, and there is one difference worth knowing about: a whole number that is a double prints here without its decimal part, so println("x: " + mySprite.getX()) says x: 0 in the browser and x: 0.0 when you run the same program yourself. The value is the same; only the way it is written out differs.
  • Class
    Description
    The AnimatedSprite class represents a sprite that can play animations.
     
    Represents a circle shape defined by its center and radius.
    The date and time of the computer the program runs on, the same values Scratch's "current [year]" and "days since 2000" blocks report.
    The Color class represents a color in the Scratch environment.
    Represents an ellipse shape.
    Represents a hitbox with a shape that can be transformed by scaling, translating, and rotating it.
    Provides predefined HTML colors as Color objects.
    Key codes for keyboard input handling.
    One of the three layers a stage draws, from back to front.
    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 Pen class represents a drawing tool that can be used to draw paths on a stage.
    Represents a polygon shape defined by its vertices.
    The Random class provides various methods for generating random values and noise.
    Represents a rectangle shape defined by its position and size.
    The RotationStyle enum represents the different rotation styles that a sprite can have in Scratch.
    Thrown when a program cannot go on, for example because a costume or a sound could not be loaded.
    Represents a generic shape that can be transformed and drawn.
    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 Text class represents a text object that can be displayed on the stage.
    Where a piece of text sits relative to its position.
    The TextStyle enum represents different styles of text that can be used.
    How pictures are smoothed when they are drawn larger or smaller than they really are.
    The Timer class provides methods for timing events in a graphical application.
    Represents a triangle shape defined by three vertices.
    A sprite for buttons, bars and other parts of a user interface.
    The Vector2 class represents a 2D vector with x and y coordinates.
    The Window class represents a singleton window for the application.