Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Three Sprite Node Collisions - When one Sprite hits two overlapping Sprites (Swift)

mattdryermattdryer 94538Posts: 5New Users Noob
I have an app that is very similar to a duck hunt type game. Multiple birds fly across the screen and you shoot balls at them. Everything works great except for the fact that if a ball hits two overlapping birds then the app crashes. Please and thank you!
func didBeginContact(contact: SKPhysicsContact) {
        var firstBody: SKPhysicsBody!
        var secondBody: SKPhysicsBody!

        if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
            firstBody = contact.bodyA
            secondBody = contact.bodyB

        }
        else {
            firstBody = contact.bodyB
            secondBody = contact.bodyA
        }

   if firstBody.categoryBitMask == ballCategory && secondBody.categoryBitMask == birdCategory {

            ballDidCollide(firstBody.node as SKSpriteNode!, bird: secondBody.node as SKSpriteNode!)
        }

Sign In or Register to comment.