Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpriteKit PhysicsBody non-rectangular collision

    pipeUp.physicsBody = SKPhysicsBody(rectangleOfSize: pipeUp.size)

in this coding I used the rectangleOfSize for collision physics body, but if I want to use by pixel just the shape of the image, what I should use instead of rectangleOfSize?

like image 297
Kim Avatar asked Feb 12 '26 23:02

Kim


1 Answers

You should make a CGPath that is the shape of your object, and use SKPhysicsBody's init(polygonFromPath path: CGPath) as described here

like image 137
Klaus Byskov Pedersen Avatar answered Feb 14 '26 15:02

Klaus Byskov Pedersen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!