I have a picture set up in spritekit that takes up the whole screen, which has its own physicsBody as follows:
I set up the touch methods so that the user "draws" on the screen with a clear color, essentially removing alpha from the picture:
As you can see, my physicsBody changes as the alpha values in the image change. Now, as I keep drawing closer and closer to another edge, the physicsBody acts the way it should, keeping everything that isnt alpha 0 part of the body:
However, when the texture is eventually split by a line with alpha value of 0, the physics body discludes one of the portions:
This is undesired behavior, as I would like to keep EVERYTHING that has an alpha value over 0 part of the body. I trie splitting the body into multiple parts, essentially meaning that if a line is drawn between them, there will be two bodies. However, this still doesn't change anything if a line is drawn within one of the bodies.
Does anyone know how I can split the bodies if they are separated? Maybe other alternatives to accomplish the same task? Thanks
Just have an
SKNode
to represent the whole thing, then add a childSKNode
with aphysicsBody
attached. Then, when you detect that the user has "split" the body in half, reduce the existing child node'sphysicsBody
where the split happens, and add a new child node with the rest of the split entity as itsphysicsBody
. If you split it multiple times you'll eventually have multiple nodes, each with its ownphysicsBody
, linked together (related) by the parentSKNode
.You can do it this way (one node with heaps of children), or create a tree structure where every split will further split each child's
physicsBody
into two children, so every node will have at most two children. This will create a binary search tree which you can use for collisions if you wish.