collision detection

Nibbie
Posts: 4
Joined: 2012.03
Post: #1
hi guys

i currently have a set of sprites all of a rectangular shape. What i wish to do is implement a color collision on the sprites. So for example the right hand side of some of the sprites might have an invisible color and if that intersects with another card with a different invisible color a collision condition is true. Does anyone know how to achieve this in cocas2d?
Quote this message in a reply
⌘-R in Chief
Posts: 1,254
Joined: 2002.05
Post: #2
Do you really need pixel-level collision detection? Using existing solutions like the polygon collision in Chipmunk would be a lot easier and faster.
Quote this message in a reply
Member
Posts: 338
Joined: 2004.07
Post: #3
Agreeing with Seth on this one-- per-pixel collision is way overkill unless you really, really, REALLY need it.

A trick I used in my first two games was to, instead of considering the rect, consider a bounding circle with diameter equal to the length or width of the rectangle, whichever was smaller. Additionally, I defined a fudge factor that shrunk or expanded that circle. It worked really well and it was easy to boot.

Justin Ficarrotta
http://www.justinfic.com
"It is better to be The Man than to work for The Man." - Alexander Seropian
Quote this message in a reply
Nibbie
Posts: 4
Joined: 2012.03
Post: #4
thanks for the response guys,

trouble is i will need different behaviour depending on which side of the rectangle has been touched and no two rectangles have the same rules. So for example for rectangle 1 touching the right side will trigger action A, for rectangle two however that same behaviour can only be triggered if the bottom is touched. Is there a a clean example out there which can put me in the right direction as to the best approach for accomplishing this?
Quote this message in a reply
⌘-R in Chief
Posts: 1,254
Joined: 2002.05
Post: #5
That doesn't require pixel-level detection. If your shapes really are just rectangles, then you can figure out which side the collision occurred on. How you do that depends on how you're doing your collision detection (from scratch, using Chipmunk, something else). Determine the necessary collision shapes of your objects, and then add your trigger response onto of that.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Collision detection using the Bullet physics engine MikeD 0 2,876 Aug 30, 2010 11:14 AM
Last Post: MikeD
  2d collision detection trouble stevemack 2 2,930 Jun 23, 2010 11:50 AM
Last Post: stevemack