Pixel Perfect Collision Detection.

Nibbie
Posts: 3
Joined: 2008.09
Post: #1
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
Quote this message in a reply
Member
Posts: 22
Joined: 2007.07
Post: #2
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.
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2008.09
Post: #3
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....
Quote this message in a reply
Member
Posts: 260
Joined: 2005.05
Post: #4
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?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Optimize the collision detection alaslipknot 1 2,881 May 12, 2013 08:02 PM
Last Post: SethWillits
  Collision detection tutorial ThemsAllTook 7 22,926 Nov 5, 2011 05:20 PM
Last Post: SethWillits
  Help with Collision Detection..(i'm almost there) carmine 1 4,724 Jun 29, 2011 12:33 PM
Last Post: ThemsAllTook
  Time Delta, collision detection mk12 19 15,813 Sep 8, 2010 06:40 PM
Last Post: AnotherJake
  Collision detection for pinball game johncmurphy 0 4,833 Sep 6, 2009 02:46 PM
Last Post: johncmurphy