I am trying to find collision detection between Two Sprits ( encircle with black color in below picture)
here is the code from which i m trying to find with the help by compairing x cordinate of both sprits but unsuccessful
have a look and tell me what is the mistake
- (void)update:(ccTime)dt {
NSLog(@"Target y %f, player y %f",target.position.y, player.position.y);
if(target.position.y==player.position.y)
// 开发者_开发百科if((target.position.x==player.position.x)&&(target.position.y==player.position.y))
// if((sprite.position.y==player.position.y)||(sprite.position.y==player.position.y))
{
Nslog (@"Matched");
//do Something
}
}
The CCNode class which is the parent of the CCSprite class has a boundingBox property of type CGRect. Using this property of the player and target objects you can check for collisions using...
if (CGRectIntersectsRect(player.boundingBox, target.boundingBox) {
// Kaboom...
}
you could have a look at CGRectIntersectsRect like shown here http://www.icodeblog.com/2009/02/18/iphone-game-programming-tutorial-part-2-user-interaction-simple-ai-game-logic/
精彩评论