Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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){
NSLog(@"Hooray!");
}

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

Thanks.

ALSO The CCSprites are named sam and tom.

share|improve this question

1 Answer 1

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

 
discard

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.