Loading...
Logo
Processing Forum

load selected pixels[]

in Programming Questions  •  2 years ago  
Hi, 

I am currently doing some collision detection by checking if my object's X and Y coordinates are over a certain color, this is done by loading the whole screen's pixels[] and checking with:

if (pixels[(int(y + 60)*width) + int(x)] == c) { 
return true;
}
else {
return false;


But, my object's X position never changes, it's always 100. Perhaps I'm looking at this the wrong way, but it seems to me I'm loading a load of pixels i really don't need every time through draw() - is there some way to only load the 100th column of pixels across, and then analyze this "slice" of the array on it's own for whether the Y position is over the specified color...?

Thanks, hope you can help

Dave

Replies(1)

" Premature optimization is the root of all evil" said one reputed programmer...
Don't try to optimize unless you experience real slow downs.
Beside, I think there is no real way to do this. If you are in P2D mode, loadPixels() does nothing (IIRC), as it acts already on an array of pixels. In default (JAVA2D) mode, Processing has to load the whole set of pixels from Java.