1
votes

I've a texture like the following one:

enter image description here

(between upper and lower blocks, it is transparent).

I want to create a SpriteNode using this and want to attach a physics body to it. How can I create a path (for the polygon of physics body) so that if another body goes through the transparent area, a collision is NOT detected? In the examples I've seen, the physics bodies were continuous ones and the path never broke at any point. Or can I attach multiple physics bodies to a single SpriteNode?

(PS: I want to draw this as a single SpriteNode).

1
Use SKPhysicsBody bodyWithBodies. - sangony
Thank you @sangony. Please Post this as answer to accept. - DroidHeaven

1 Answers

2
votes

You can use (SKPhysicsBody *)bodyWithBodies:(NSArray *)bodies to create two or more physics bodies for one SKSpriteNode.

Apple Docs: The shapes of the physics bodies passed into this method are used to create a new physics body whose covered area is the union of the areas of its children. These areas do not need to be contiguous. If there is space between two parts, other bodies may be able to pass between these parts. However, the physics body is treated as a single connected body, meaning that a force or impulse applied to the body affects all of the pieces as if they are held together with an indestructible frame.