Pixel Perfect Collision
Monkey Forums/Monkey Programming/Pixel Perfect Collision
| ||
Hey, I need to check where the user touches the screen. The problem is that 2 objects can overlap. ![]() When the user touches the red area, I could check if the foreground object is transparent in that area. Then it would be easy to determinate (something like objectImage.ReadPixels) How could I achieve this? PS: I don't think it's possible with ReadPixels because I am drawing the background before the objects. |
| ||
It's possible if you use a separate image for bit-based collision testing. You could store all your images compactly as arrays of bits (i.e. two-colour images) and do collision testing in software, for example. Or you could draw everything to the back-buffer in a format suited to collision testing, do your tests, then clear it and draw the proper output image. |
| ||
So I should do that with ReadPixels? |
| ||
<double post> |
| ||
There is no image.ReadPixels. Readpixels works with the backbuffer in the onRender event. Like Gerry said, for each image, render it seperately, read the buffer, store it inside an array and alter compare these arrays with each other. |
| ||
check the code archives, therevills posted code to do this. |
| ||
TA DA: http://www.monkeycoder.co.nz/Community/posts.php?topic=3488 ;) |
| ||
Thanks, will try that :) |