我们使用下面的代码在cocos2d中获取sprite的碰撞区域。
CGRect heroRect = [heroBird boundingBox];
if(CGRectContainsPoint(heroRect, bullet.position))
如何在sprite-kit中获取boundingBox?
答案 0 :(得分:2)
SKSpriteNode *heroBird;
heroBird = [SKSpriteNode spriteNodeWithImageNamed:@"heroBird.png"];
//heroBird rect can be set to whatever you like, shapes,rects,circles
heroBird.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:heroBird.size];
// set heroBird collision, category and contact bitmasks
// detect using didBeginContact method
CGRect heroRect = heroBird.frame;
答案 1 :(得分:2)