iDevGames Forums
Pixel Perfect Collision Detection. - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Pixel Perfect Collision Detection. (/thread-1695.html)



Pixel Perfect Collision Detection. - Maxwelldoggums - Mar 2, 2009 04:04 PM

I'm very new to Cocoa, and am writing a simple sprite game in which the player controls a tank, and simply drives to the right shooting various enemies along the way. I've gotten the drawing code down, have it updating, along with other basic stuff like that. I'm really in a fix here though. I am trying to find out how to perform pixel (or at least every other pixel) perfect tests between a point, and an NSImage, so that I can test if the ground contains a point at (x,y)... The tank should be able to drive along uneven ground, up hills under platforms, ect.

So I figured that it would be best if I could write simple code to test for transparency on the map, so that I can tell where the ground starts... but I don't think this would be efficient enough. Right now the image I'm working with for the level is (I know it's crazy) 500 X 10,000 pixels, so it's a lot to ask.

I would appreciate it if anyone could give me any ideas as to how to go about solving this problem.

Thanks in advance,
-Max


Pixel Perfect Collision Detection. - Muskrat - Mar 2, 2009 08:56 PM

I think if you want pixel perfect collision you should at least narrow down the possibilities by subdividing the level into rectangular regions of a reasonable size and then checking which regions the bounding box of the tank collides with. Then you only need to check for collisions in those limited areas rather than the whole map.


Pixel Perfect Collision Detection. - Maxwelldoggums - Mar 3, 2009 02:59 PM

Thanks! You've given me the idea for a way to do it. I can just test the pixel color and see if it's transparent at the given point! that way I only need to test it once, and I can get exactly what I want....


Pixel Perfect Collision Detection. - Ingemar - Mar 21, 2009 03:18 PM

Do you mean that you transform every pixel in your tank to the background coordinates and test? That sounds like lots of pixel chewing for the CPU.

What about object-object?