title: Add boundaries to an SKScene
body: <p>I'm trying to write a basic game using Apple's Sprite Kit framework. So far, I have a ship flying around the screen, using SKPhysicsBody. I want to keep the ship from flying off the screen, so I edited my update method to make the ship's velocity zero. This works most of the time, but every now and then, the ship will fly off the screen.</p>
  
  <p>Here's my update method.</p>
  
  <pre><code>// const int X_MIN = 60;
  // const int X_MAX = 853;
  // const int Y_MAX = 660;
  // const int Y_MIN = 60;
  // const float SHIP_SPEED = 50.0;
  
  - (void)update:(CFTimeInterval)currentTime {
      if (self.keysPressed &amp; DOWN_ARROW_PRESSED) {
          if (self.ship.position.y &gt; Y_MIN) {
              [self.ship.physicsBody applyForce:CGVectorMake(0, -SHIP_SPEED)];
          } else {
              self.ship.physicsBody.velocity = CGVectorMake(self.ship.physicsBody.velocity.dx, 0);
          }
      }
  
      if (self.keysPressed &amp; UP_ARROW_PRESSED) {
          if (self.ship.position.y &lt; Y_MAX) {
              [self.ship.physicsBody applyForce:CGVectorMake(0, SHIP_SPEED)];
          } else {
              self.ship.physicsBody.velocity = CGVectorMake(self.ship.physicsBody.velocity.dx, 0);
          }
      }
  
      if (self.keysPressed &amp; RIGHT_ARROW_PRESSED) {
          if (self.ship.position.x &lt; X_MAX) {
              [self.ship.physicsBody applyForce:CGVectorMake(SHIP_SPEED, 0)];
          } else {
              self.ship.physicsBody.velocity = CGVectorMake(0, self.ship.physicsBody.velocity.dy);
          }
      }
  
      if (self.keysPressed &amp; LEFT_ARROW_PRESSED) {
          if (self.ship.position.x &gt; X_MIN) {
              [self.ship.physicsBody applyForce:CGVectorMake(-SHIP_SPEED, 0)];
          } else {
              self.ship.physicsBody.velocity = CGVectorMake(0, self.ship.physicsBody.velocity.dy);
          }
      }
  }
  </code></pre>
  
  <p>At first, I used <code>applyImpulse</code> in <code>didBeginContact</code> to push the ship back. This made the ship bounce, but I don't want the ship to bounce. I just want it to stop at the edge.</p>
  
  <p>What is the right way to make the ship stop once it reaches the edge? The code above works most of the time, but every now and then the ship shoots off screen. This is for OS X—not iOS—in case that matters.</p>