title: Swift: detecting bodyAtPoint. Always nil
body: <p>I'm struggling to discover why I cannot detect a <code>bodyAtPoint</code> with SpriteKit. <code>bodyAtPoint</code> always returns <code>nil</code>, even when it appears I'm always tapping the sprite node.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>...
  
  let spaceship = SKSpriteNode(color: UIColor.blueColor(), size: CGSizeMake(100, 100))
  
  override func didMoveToView(view: SKView) {
      /* Setup your scene here */
  
      var borderBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
      self.physicsBody = borderBody
      self.physicsBody.friction = 0.0
      self.physicsWorld.gravity = CGVectorMake(0.0, 0.0)
  
      spaceship.name = "spaceship"
      spaceship.position = CGPointMake(400, 300)
  
      var bodySize = CGSizeMake(spaceship.size.width / 1.15, spaceship.size.height / 1.15);
      spaceship.physicsBody = SKPhysicsBody(rectangleOfSize: bodySize)
  
      spaceship.physicsBody.dynamic = false
      spaceship.physicsBody.restitution = 1.0
      spaceship.physicsBody.friction = 0.0
      spaceship.physicsBody.linearDamping = 0.0
      spaceship.physicsBody.allowsRotation = false
  
      self.addChild(spaceship)
  }
  
  override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
  
      /* Called when a touch begins */
      super.touchesBegan(touches, withEvent: event)
  
      var touch : UITouch! = touches.anyObject() as UITouch
      var touchLocation : CGPoint! = touch.locationInNode(self)
  
      if self.physicsWorld.bodyAtPoint(touchLocation) {
          NSLog("true")
      } else {
          NSLog("false")
      }
  }
  
  ...
  </code></pre>
  
  <p>RESULTS:</p>
  
  <p><code>spaceship.physicsBody</code> outputs:</p>
  
  <pre><code>&lt;SKPhysicsBody&gt; type:&lt;Rectangle&gt; representedObject:[&lt;SKSpriteNode&gt; name:'spaceship' texture:['nil'] position:{400, 300} size:{100, 100} rotation:0.00]
  </code></pre>
  
  <p><code>touchLocation</code> output:</p>
  
  <pre><code>(411.943664550781,553.014099121094)
  </code></pre>
  
  <p><code>self.physicsWorld.bodyAtPoint(touchLocation)</code> is always:</p>
  
  <pre><code>nil
  </code></pre>
  
  <p>... Therefore the conditional always returns <code>false</code>.</p>
  
  <p>Can anybody explain where I'm going wrong? I want to ultimately detect a touch on a sprite node and perform an action.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Even if I simplify to the following I still always get <code>false</code>:</p>
  
  <pre><code>override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
  
      ...
  
      for touch: AnyObject in touches {
          let location = touch.locationInNode(self)
  
          if self.physicsWorld.bodyAtPoint(location) {
              NSLog("true")
          } else {
              NSLog("false")
          }
      }
  }
  
  ...
  </code></pre>