Search code examples
iphoneobjective-ccocos2d-iphonecollision-detectionsprite

cocos2d pixel collision detection


i am currently writing a game with a number of rectangles (say 30), if a user clicks on one of the four sides a certain action will need to be taken. Trouble is each card will have the same side which will perform this action. For example with rectangle 1 the side which will perform this action will be the left, but rectangle 3 the side will be the top side. My guess is a pixel collision detection is needed here. What do you guys think? Also is there a good example on pixel collision using cocos2s out there?


Solution

  • You can simply use following code

    if (CGRectIntersectsRect(Rect1, Rect2)) 
    {
         //Your code ...                
    }   
    

    USING above CGRectIntersectsRect you can detect the collision pixels within a rectangular area.