SpriteKit中的Sprite的Boundingbox

时间:2014-03-14 16:41:47

标签: sprite-kit

我们使用下面的代码在cocos2d中获取sprite的碰撞区域。

CGRect heroRect = [heroBird boundingBox];
if(CGRectContainsPoint(heroRect, bullet.position))

如何在sprite-kit中获取boundingBox?

2 个答案:

答案 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)

使用以下行获取边界框:

CGRect heroRect = [heroBird calculateAccumulatedFrame]

另见Apple Docu