Hello everyone,
I would like to have so SKSpriteNodes can take care of there own contact detection.
Much like Unity have there own `OnTriggerEnter` methods on there GameObjects.
But I do not know how to achieve that in SpriteKit, some help would much appriciated
Example how I would "like" it to work:
import SpriteKit
class Ball: SKSpriteNode, SKPhysicsContactDelegate {
func didBegin(_ contact: SKPhysicsContact) {
print("INSIDE BALL: ",contact.bodyA.node?.name, contact.bodyB.node?.name)
}
init(x: Int, y: Int) {
physicsWorld.contactDelegate = self ????
//setting up Physicsbody etc
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
import SpriteKit
import GameplayKit
class GameScene: SKScene, SKPhysicsContactDelegate {
override func didMove(to view: SKView) {
physicsWorld.contactDelegate = self
}
func didBegin(_ contact: SKPhysicsContact) {
print("INSIDE MAIN: ",contact.bodyA.node?.name, contact.bodyB.node?.name)
}
Or how do you manage large amount of contact logic?
Thanks for any help and sorry if the questions is weirdly formulated