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

public class Pixels extends Object
The colours of everything a stage has drawn, one number per pixel.

Reached through stage.getPixels():


 int[] colours = this.getPixels().main();
 

These layers live on the graphics card, and reading them back is both slow and only possible while the stage is drawing. Asking from somewhere else - a sprite's run(), say - gives an empty array. Treat this as a low-level hook for drawing tricks rather than as a way to sense colours: a Scratch-style "touching colour" check would have to read the whole screen back every frame, which is far too slow for the machines this library is meant to run on.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Pixels(processing.core.PGraphics mainBuffer, processing.core.PGraphics backgroundBuffer, processing.core.PGraphics foregroundBuffer)
    Creates the pixel access for a stage.
  • Method Summary

    Modifier and Type
    Method
    Description
    int[]
    Returns the pixels of the background layer, where the pen and stamps draw.
    int[]
    Returns the pixels of the foreground layer.
    int[]
    Returns the pixels of the layer the sprites are drawn on.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Pixels

      public Pixels(processing.core.PGraphics mainBuffer, processing.core.PGraphics backgroundBuffer, processing.core.PGraphics foregroundBuffer)
      Creates the pixel access for a stage.
      Parameters:
      mainBuffer - where the sprites are drawn
      backgroundBuffer - where the background is drawn
      foregroundBuffer - where the foreground is drawn
  • Method Details

    • main

      public int[] main()
      Returns the pixels of the layer the sprites are drawn on.
      Returns:
      one colour per pixel
    • background

      public int[] background()
      Returns the pixels of the background layer, where the pen and stamps draw.
      Returns:
      one colour per pixel
    • foreground

      public int[] foreground()
      Returns the pixels of the foreground layer.
      Returns:
      one colour per pixel