I created a 2D light collision algorithm which generates a black and white image. I am then using this pixel data to modify a second overlay image, which starts full black. Each frame:
* If the light image pixel is white, set the "same" overlay pixel to transparent
* If the light image pixel is black, but the "same" overlay pixel is transparent, set it to "dim"
This only works
on the first frame.
After pulling my hair out for a while, I
think there's an underlying problem with processing... or I have completely missed something. What I'm seeing is this: the pixel array of the light image never updates after the first frame, even though the image is being constantly updated.
I created a simplified program to demonstrate this. The "light" is just an arc that rotates. The overlay is just trying to copy the light's pixels one to one each frame. You can uncomment image(light, 0, 0) to see that the light is updating correctly. But other than that... ???
- PGraphics overlay, light;
- float theta;
- void setup() {
- size(200, 200);
- // Initialize the overlay
- overlay = createGraphics(200, 200, JAVA2D);
- overlay.beginDraw();
- overlay.background(0);
- overlay.endDraw();
- // Initialize the light
- light = createGraphics(200, 200, JAVA2D);
- }
- void draw() {
- background(255, 0, 0);
- // Render the light to a buffer
- theta += radians(2);
- light.beginDraw();
- light.background(0);
- light.fill(255);
- light.arc(100f, 100f, 200f, 200f, theta, theta + PI/4);
- light.endDraw();
- // Transfer the light pixel information to the overlay
- for (int i = 0; i < overlay.width * overlay.height; i++) {
- overlay.pixels[i] = light.pixels[i];
- }
- overlay.updatePixels();
- image(overlay, 0, 0);
- // Uncomment to see the light move
- //image(light, 0, 0);
- }
1