It actually works without the PGraphics :)
It even seems to be a bit quicker, but I still have my values getting stuck sometimes
//MAIN
Quote:import processing.video.*;
int numPixels;
int[] backgroundPixels;
Capture video;
Zone playerOne, playerTwo;
void setup() {
// Change size to 320 x 240 if too slow at 640 x 480
size(640, 480, P2D);
video = new Capture(this, width, height, 24);
video.settings();
numPixels = video.width * video.height;
// Create array to store the background image
backgroundPixels = new int[numPixels];
// Create Zone: zone size, x, y, name
playerOne = new Zone(200, 10, 10, "Player One");
playerTwo = new Zone(200, width-210, 10, "Player Two");
loadPixels();
}
void draw() {
if (video.available()) {
video.read(); // Read a new video frame
//image(video, 0, 0); //Display video for knowing where you are
video.loadPixels(); // Make the pixels of video available
playerOne.detect();
playerTwo.detect();
}
}
// When a key is pressed, capture the background image into the backgroundPixels
// buffer, by copying each of the current frame’s pixels into it.
void keyPressed() {
video.loadPixels();
arraycopy(video.pixels, backgroundPixels);
}