1

Hey so i have this game where you collect gems to unlock characters, i have the gems spawning and in my didBeginContct i have collision detecting setup, my problem is that it detects more than one touch and adds more than one gem! Please help i tried fixing it myself but i couldnt get the logic working right! Thanks in advance

func didBeginContact(contact: SKPhysicsContact) {
    let fadeIn = SKAction.fadeAlphaTo(1, duration: 0.2)
    let contactMask = contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask

    switch(contactMask) {

    case colisionType.Player.rawValue | colisionType.Triangle.rawValue: {

        }

    case colisionType.Player.rawValue | colisionType.Diamond.rawValue:

        diamond.removeFromParent()
        gems++

    default:
        return
    } 
}
Eli
  • 668
  • 2
  • 13
  • 37
  • Are you missing some code in your post? It seems the above wouldn't even compile without a switch. – Aderstedt Aug 10 '15 at 12:07
  • Yeah I have a switch statement I just didn't put it in because it was late and it didn't directly help but yeah there is a switch statement above – Eli Aug 10 '15 at 20:51
  • There we go i updated the code for you :D – Eli Aug 10 '15 at 21:01
  • Have you set the categoryBitMask properties on the bodies correctly? – Aderstedt Aug 11 '15 at 05:14
  • yeah the collision detection works fine its just because its detecting two touches really quickly before the node is removed! – Eli Aug 11 '15 at 05:31
  • Oh, so didBeginContact is called twice? Apparently this is a known issue, see e.g. this SO question: http://stackoverflow.com/questions/27956637/didbegincontact-is-being-called-multiple-times-for-the-same-skphysicsbody?rq=1 – Aderstedt Aug 11 '15 at 05:38
  • thanks for your help! Iv got it working now :) – Eli Aug 11 '15 at 09:40

0 Answers0