0
-(void)handleContact:(SKPhysicsContact*)contact{

    NSArray *nodeNames = @[contact.bodyA.node.name, contact.bodyB.node.name];

    if ([nodeName containsObject:player] && [nodeName containsObject:window] {  //player and windows are defined strings which are set in SKSpriteNode names

        Do something to window

    } else if ([nodeName containsObject:player] && [nodeName containsObject:door])

        Do something to door
    } //Continue another 10 times with different defined strings except player

}

Would this sort of code be ideal for collision detection or is there a better way i can face this?

Mutch95
  • 271
  • 3
  • 14
  • 1
    You would be better testing the CollisionBitMasks here. That's what they're there for. Also, you don't have to actually **handle** the collision here. Just use it as a routing method. I.e. From here run the `player:didCollideWithEnemy:` or something like that. – Fogmeister Apr 22 '14 at 10:12
  • @Fogmeister but in a sense I still need to create multiple if statements to check the collisionBitMask? – Mutch95 Apr 22 '14 at 10:18
  • Have a look at this: http://stackoverflow.com/a/20604762/2043580 – ZeMoon Apr 22 '14 at 12:01

0 Answers0