Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 2 CCSprites and I want to tell if their x and y are equal I tried this:

if(sam.position.x == tom.position.x && sam.position.y == tom.position.y){

Although I do not think this is the right way to do this. Could anyone help me?


ALSO The CCSprites are named sam and tom.

share|improve this question
up vote 2 down vote accepted

That works, but might cause problems because of floats. It would be better to factor in some margin of error.. maybe half a screen-point... that would then look like this

if(fabsf(sam.position.x - tom.position.x) < 0.5f && fabsf(sam.position.y - tom.position.y) < 0.5f)

Of course you can change the "threshold/accuracy" by increasing or decreasing the 0.5f value.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.