开发者

How to Find Collision Detection between CCSprits?

开发者 https://www.devze.com 2023-02-21 23:09 出处:网络
I am trying to find collision detection between Two Sprits ( encircle with black color in below picture)

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  
    }
}

How to Find Collision Detection between CCSprits?


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消