title: Keep model from going out of a window
body: <p>Hi guys so i am making a simple game, and following this tutorial <a href="http://www.zekechan.net/asteroids-html5-game-tutorial-2/" rel="nofollow">Here</a></p>
  
  <p>I am up to the bit for which the ship can go out of bounds and then re appear onto the other side using this code: </p>
  
  <pre><code>checkBoundaries: function (sprite) {
          if (sprite.x &lt; 0) {
              sprite.x = game.width;
          } else if (sprite.x &gt; game.width) {
              sprite.x = 0;
          } 
  
          if (sprite.y &lt; 0) {
              sprite.y = game.height;
          } else if (sprite.y &gt; game.height) {
              sprite.y = 0;
          }
      },
  </code></pre>
  
  <p>However i am new to this and learning so i was wondering what is the way to keep it from not going out of bounds, so it hits like a wall and it cant go out of bounds and re appear but just stay there </p>
  
  <p>Thanks again for the help </p>