0

I have a sprite that i initialized as a SKSPriteNode bouncing continuously off another sprite also initialized the same way.

I can't figure out collision between the two, and nothing on stack has helped so far.

I have this set up to move the sprite using gravity.

 self.physicsWorld.gravity = CGVector(dx: 0.0, dy: -2.0)
 self.physicsWorld.contactDelegate = self     

this is how I'm trying to check

if bounceHex.physicsBody?.collisionBitMask == 
   collider.physicsBody?.collisionBitMask
    {
        score = score+1
        print(score)

    }

nothing happens with this code. I only want the score to increase with each bounce

WhatsGoood
  • 17
  • 4
  • Hi and welcome to SO. You are missing so much code that it's easier to give you a working example - please see my answer below. You're missing 1 of the 2 steps to set up the contact delegate, the creation of the physics bodies, the allocation of the category and contactTest bitmasks, the implementation of the 'didBegin' function and the logic in 'didBegin' to ascertain whcihn 2 nodes have collided., – Steve Ives Jun 20 '19 at 12:29
  • ah thank you so much! As you can tell SO isn't the only thing I'm new to - swift is pretty different from what I've used before. – WhatsGoood Jun 20 '19 at 17:13
  • The Ray Wenderlich tutorials aren’t pretty good. Eventually it’ll click and you’ll wonder where the confusion came from – Steve Ives Jun 20 '19 at 20:59

1 Answers1

0

My step-by-step guide for collisions and contacts: https://stackoverflow.com/a/51041474/1430420

And a guide to collision and contactTest bit masks: https://stackoverflow.com/a/40596890/1430420

Manipulating bit masks to turn individual collision and contacts off and on. https://stackoverflow.com/a/46495864/1430420

Steve Ives
  • 7,894
  • 3
  • 24
  • 55