Pixel Perfect Collision

Monkey Forums/Monkey Programming/Pixel Perfect Collision

Shinkiro1(Posted 2012) [#1]
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.


Gerry Quinn(Posted 2012) [#2]
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.


Shinkiro1(Posted 2012) [#3]
So I should do that with ReadPixels?


Shinkiro1(Posted 2012) [#4]
<double post>


MikeHart(Posted 2012) [#5]
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.


NoOdle(Posted 2012) [#6]
check the code archives, therevills posted code to do this.


therevills(Posted 2012) [#7]
TA DA:

http://www.monkeycoder.co.nz/Community/posts.php?topic=3488

;)


Shinkiro1(Posted 2012) [#8]
Thanks, will try that :)