title: Swift: sprite collision detection without making physics bodies?
body: <p>Alright, so I'm fairly new to sprite kit and I'm working in Swift. I have 2 sprite nodes, <code>savior</code> and <code>chicken1</code>. <code>savior</code> has a physics body and this is how I set it up: </p>
  
  <pre><code>var saviorTexture = SKTexture(imageNamed: "1.png")
  saviorTexture.filteringMode = SKTextureFilteringMode.Nearest
  
  savior = SKSpriteNode(texture: saviorTexture)
  savior.setScale(0.2)
  savior.position = CGPoint(x: self.frame.size.width * 0.5, y: self.frame.size.height * 0.2)
  savior.physicsBody?.dynamic = true
  savior.physicsBody?.allowsRotation = false
  savior.physicsBody = SKPhysicsBody(rectangleOfSize: CGSizeMake(savior.size.width, savior.size.height))
  
          self.addChild(savior)
  </code></pre>
  
  <p><code>chicken1</code> right now does not have a physics body:</p>
  
  <pre><code>var chickenTexture = SKTexture(imageNamed: "block1")
  
          chicken1 = SKSpriteNode(texture: chickenTexture)
          chicken1.setScale(0.75)
          chicken1.position = CGPoint(x: self.size.width * 0.38, y: self.size.height * 1.2)
          self.addChild(chicken1)
  </code></pre>
  
  <p>I need to know how I can have collision detection (i.e. if savior and chicken1 touch, execute this) between these objects, preferably without making <code>chicken1</code> a physics body. </p>
  
  <p>When I make <code>chicken1</code> a physics body, suddenly it becomes erratic and moves other objects around. </p>
  
  <p>If there is not a way to do collision detection without physics, how can I make <code>chicken1</code> a physics body that is NOT affected by anything and just goes right through the other physics bodies?</p>
  
  <p>EDIT**************</p>
  
  <p>So I followed <a href="https://stackoverflow.com/questions/26270504/beginner-swift-sprite-kit-node-collision-detection-help-skphysicscontact">beginner swift sprite kit - node collision detection help (SKPhysicsContact)</a> and have: </p>
  
  <ol>
  <li><p>changed my class to be a <code>SKPhysicsContactDelegate</code>: </p>
  
  <p>class GameScene: SKScene, SKPhysicsContactDelegate {</p></li>
  <li><p>Written the following:</p>
  
  <pre><code>    self.physicsWorld.contactDelegate = self
  
      savior.physicsBody?.categoryBitMask = saviorCategory
      savior.physicsBody?.contactTestBitMask = animalCategory
      savior.physicsBody?.collisionBitMask = 0
  
      chicken1.physicsBody?.categoryBitMask = animalCategory
      chicken1.physicsBody?.contactTestBitMask = saviorCategory
      chicken1.physicsBody?.collisionBitMask = 0
  
      func didBeginContact(contact: SKPhysicsContact) {
  
      var saviorPhysics: SKPhysicsBody
      var chicken1Physics: SKPhysicsBody
  
      if contact.bodyA.categoryBitMask &lt; contact.bodyB.categoryBitMask
      {
          saviorPhysics = contact.bodyA
          chicken1Physics = contact.bodyB
      }
      else {
          saviorPhysics = contact.bodyB
          chicken1Physics = contact.bodyA
      }
  
      if saviorPhysics.categoryBitMask == 0 &amp;&amp; chicken1Physics.categoryBitMask == 1 {
          self.chicken1.removeFromParent()
      }
  
  }
  </code></pre></li>
  </ol>
  
  <p>I ran it and there were no errors, but it doesn't work. </p>