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.


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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