Class Pixels

java.lang.Object
org.openpatch.scratch.Pixels

public final class Pixels extends Object
The pixels of the stage or of an image file, to read colours from. Coordinates count pixels from the top left corner (0, 0).
Pixels terrain = Pixels.of("assets/terrain.png");
boolean solid = terrain.getColor(10, 20).getAlpha() > 0;

Pixels screen = Pixels.of(this.getStage());

The stage's pixels are what its world layers show at that moment: backdrop, stage colour, pen strokes, stamps and sprites with their effects, the same as colour sensing sees. Texts, shaders and the UI layer are not included.

  • Method Details

    • of

      public static Pixels of(Stage stage)
      The stage's pixels as they are now.
      Parameters:
      stage - the stage
      Returns:
      its pixels, at stage size
    • of

      public static Pixels of(String imagePath)
      The pixels of an image file.
      Parameters:
      imagePath - the image
      Returns:
      its pixels
    • getWidth

      public int getWidth()
      Returns:
      the width in pixels
    • getHeight

      public int getHeight()
      Returns:
      the height in pixels
    • getColor

      public Color getColor(int x, int y)
      Parameters:
      x - pixels from the left edge
      y - pixels from the top edge
      Returns:
      the colour there, or transparent black outside
    • getArgb

      public int getArgb(int x, int y)
      Parameters:
      x - pixels from the left edge
      y - pixels from the top edge
      Returns:
      the colour there packed as alpha, red, green, blue, or 0 outside