Computer Science Canada

whatdotcolor workaround?

Author:  vlovich [ Sun Jun 01, 2003 2:38 pm ]
Post subject:  whatdotcolor workaround?

I'm trying to store the color of every pixel on the screen into a 2d array. Any faster way to do this than:

for x:0..maxx
for y:0..maxy
array(x,y) := whatdotcolor(x,y)
end for
end for

I need this for collision detection. If there is a bounding intersection and certain pixels are not the background color, a collision occured.

Author:  Andy [ Sun Jun 01, 2003 2:43 pm ]
Post subject: 

dude man, the computer does that pretty fast, why do u want to do it any faster? if you plan to put that in a loop i suggest this
code:

for x:1..maxx
for y:1..maxy
if whatdotcolor(x,y)not=array(x,y) then
array(x,y):=whatdotcolor(x,y)
end if
end for
end for


this only changes the sectors in the arrays that changed
you could also go one step further by finding out the coordinates of the moving object and just change the sectors of the array within a cetrain range

Author:  vlovich [ Sun Jun 01, 2003 2:51 pm ]
Post subject: 

you focused on the wrong part of my message. the thing that takes a really long time is storing all the pixel values for the screen into an array. the pixel checking is fast enough, i agree. but the background storage takes quite a while

Update: I think I see what the problem is. I guess I wasn't clear enough.
My background is going to be static. It's not that I have to worry about changing the background and updating the array. The original storage into the array is slow, and updating it isn't even part of my program. And another thing, your suggestion to update is even slower than simply recreating the array since in the best case you call it as many times as mine and in the worst case twice as much (the background has completely changed and you call it in the if statement and in setting the array value)


: