0
votes

We used below code to get sprite's collision area in cocos2d.

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

How to get boundingBox in sprite-kit?

2

2 Answers

2
votes
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;
2
votes

Use the following line to get the bounding box:

CGRect heroRect = [heroBird calculateAccumulatedFrame]

see also Apple Docu