Reputation: 360
I have a stack of blocks (think Angry Birds) and when a projectile hits them they fall over like you'd expect. However, this only works if I create the physicsBody like so:
self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.size];
If, however, I create the physics body like this:
CGRect r = CGRectMake(-self.size.width/2, -self.size.height/2, self.size.width, self.size.height);
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:r];
Then the collision is there, but the blocks are not affected by it. The projectiles bounce off of it, but do not cause the blocks to move at all. My categoryBitMask and collisionBitMask are correct - they work with -bodyWithRectangleOfSize, but -bodyWithEdgeLoopFromRect does not.
Is this a SpriteKit bug, or am I missing something?
Thanks,
-Brian
Upvotes: 1
Views: 879
Reputation: 20274
Have a look at the SKPhysicsBody Class Reference.
You will find that the various class methods for creating physicsBodies are listed under two categories, namely Volume-based and Edge-based physics bodies.
bodyWithRectangleOfSize:
returns a volume-based physicsBody whereas bodyWithEdgeLoopFromRect
returns an edge-based physicsBody.
In the overview of the same document, the difference between the two is explained as:
Sprite Kit supports two kinds of physics bodies, volume-based bodies and edge-based bodies. When you create a physics body, its kind, size, and shape are determined by the constructor method you call. An edge-based body does not have mass or volume, and is unaffected by forces or impulses in the system. Edge-based bodies are used to represent volume-less boundaries or hollow spaces in your physics simulation. In contrast, volume-based bodies are used to represent objects with mass and volume.
Upvotes: 3