How do you test for collisions in Xcode?

In Apple’s Xcode, how do you test for collisions between two possibly moving objects?

My current code is this:

if (rock.center.x >= player.frame.origin. x && rock.center.x <= player.frame.size. width &&
   rock.center.y >= player.frame.origin.y && rock.center.y <= player.frame.size.height) {

but something is off, the code is not working. I do not know what is wrong- it looks correct. Can someone tell me how to correctly test for collisions in Xcode?

This question is answered in the cComments section, powered by Yahoo! Answers:

One thought on “How do you test for collisions in Xcode?”

  1. float dx = rockl. frame. origin. x – player. frame. origin. x;float dy = rock. frame. origin. y – player. frame. origin. y;float d = sqrt(dx*dx + dy*dy);suppose radius of rock is 10if (d< 10){//collision}

Leave a Reply to Arpita Cancel reply

Your email address will not be published. Required fields are marked *