SpriteKit Contact Detection

Cecil_Ma
Oct 26, 2020
import SpriteKit

class MyScene: SKScene, SKPhysicsContactDelegate {
override func didMove(to view: SKView) {
...
physicsWorld.contactDelegate = self
}

func didBegin(_ contact: SKPhysicsContact) {
guard let name1 = contact.bodyA.node?.name else {return}
guard let name2 = contact.bodyB.node?.name else {return}
// logic deal with the contact
}
}

--

--

Cecil_Ma
0 Followers

System engineer. Indie iOS developer. Fan of table tennis and darts.