I started studying the Sprite Kit Game in iOS and I am want to find out how can I detect if a collision occurred when the ball entered in the hoop.
To make things easier to understand. My at my basketball hoop I have 2 corners (they are red and easy to see, they stand out), they have collision attached to them and if ball hits them, it gets trowed.
My question: I want to get noticed when the ball hits any of the corners or if the ball entered the hoop without hitting any of the 2 corners. (like a way to score differentiate normal throws from perfect throws)
UPDATED:
How do I set a flag to the corners? Can you point to the functions I need to use?
I have a node which notifies me if the ball entered the hoop, it's the steel bar in the middle of the hoop, when it collides, it adds my score.
func didBegin(_ contact: SKPhysicsContact)
{
// check for the ball contacting the scoreZone (scoreZone is the steel bar)
guard let ballBody = ball.physicsBody, let scoreBody = score_zone.physicsBody else {
return
}
// it doesn't matter who touches who, so just use array "contains" to handle both cases
let bodies = [contact.bodyA, contact.bodyB]
if bodies.contains(ballBody) && bodies.contains(scoreBody) && should_detect_score {
// add score
add_score()
}
}