I'm trying to create a single physics body from several other bodies using the SKPhysicsBody(bodies:) init.
I have nodes throughout my scene that have physics bodies attached to them, and I want to consolidate them into a single physics body. I'm enumerating through the nodes of the scene and picking out the nodes I want to target. I'm creating the physics body at the creation of those nodes like this:
node.physicsBody = SKPhysicsBody(rectangleOf: node.size)
node.physicsBody?.isDynamic = false
Then I add the physics body to an array of SKPhysicsBodies like this:
self.allNodePhysicsBodies.append(node.physicsBody)
I then create the conglomerate physics body like this:
let conglomeratePhysicsBody = SKPhysicsBody(bodies: self.allNodePhysicsBodies)
I've tried several different ways of adding the physics bodies to the scene: By creating an SKNode or SKSpriteNode and adding the physics bodies to it and the adding it to the scene, or setting the scene's physics body conglomeratePhysicsBody. All of these methods end up with the physics bodies all aligned at the bottom of the scene (not positioned around the scene like they should be). When I print out the conglomeratePhysicsBody to the console, I get this message: <SKPhysicsBody> type:<Compound> representedObject:[(null)].
Is there something I'm missing that is keeping the physics bodies from appearing where the nodes are?
I should add that I can see the physics bodies by using skView.showsPhysics = true.