Doubt about bounding boxes SpriteKit

1

How can you create a bounding box that collides with a circular shape, being this triangular?

    
asked by Ramon Alvarez Mora 26.09.2017 в 18:12
source

1 answer

0

You need to use one of the polygonal type

let polygonalSpaceShip = SKSpriteNode(texture: spaceShipTexture)
let path = CGMutablePath()
path.addLines(between: [CGPoint(x: 0, y: 0), CGPoint(x: 50, y: 50), CGPoint(x: 0, y: 50),
                        CGPoint(x: 0, y: 0)]) //son 4 porqué el ultimo vuelve al origen

Example of SKPhysicsBody

Although depending on your sprite you can try using the alpha channel

let texturedSpaceShip = SKSpriteNode(texture: spaceShipTexture)
texturedSpaceShip.physicsBody = SKPhysicsBody(texture: spaceShipTexture,
                                              size: CGSize(width: circularSpaceShip.size.width,
                                                           height: circularSpaceShip.size.height))
    
answered by 26.09.2017 / 22:38
source