The game Supertype is incredible.
I was thinking about making an app similar to it.
Is there any easy way to turn the text of a SKLabelNode into a Physics Body?
for example, I want to have the letter 'A' become a literal Physics Body
- Is there any simplistic way to achieve this without having to actually define each cgPath?
- I guess I could make the 'A' a SKSpriteNode, but this seems poor.
Also,
I've had many problems turning SKSpriteNodes into Physics Bodies. I can easily turn a single image into a physicsBody, but if it's an image broken apart by invisible segments, things brake. Swift chooses a specific segment to become a physicsBody.
• I'm also so upset, since you can't define a concave shape and make a Physics Body. But you can have concave contiguous images become physics bodies nicely.
Last,,
It would be very nice to have a word turn into a Physics Body, and with a Boolean, define it to fall apart or stick together. Is there a way to do this?
(I'm thinking I can do it by clumping an array of them in the initialization: [SKPhysicsBody])
A SKLabelNode
doesn't have a physics body, so you can not apply physics directly to it. What you could do is create them as a set of SKSpriteNodes
and assign an image of each letter to the body texture.
To "turn the physics body on and off", you should toggle the node's property isDynamic
. For other effects, you can play with affectedByGravity
property and the collision and the contact bitMasks, depending on what you want.
To make the collision feel more real, you can use SKPhysicsContactDelegate
, so you can automatically "draw" a physics body with the exact shape of the letters. Something like this:
letterNode.physicsBody = SKPhysicsBody(texture: letterTexture, alphaThreshold: 1.0, size: letterTexture.size())
To handle the collisions and contacts, don't forget to set the contactDelegate in your scene, like this:
self.physicsWorld.contactDelegate = self