title: Boundary Detection
body: <p>I'm working on a simple script that will allow users to create games. I'm trying to use as simple an approach as possible for users, so I've have setup an image-to-path system, with some great help from @markE:</p>
  
  <p><a href="https://stackoverflow.com/questions/23211721/canvas-black-and-white-image-to-shape/23213285#23213285">Canvas Black and White Image to Shape</a></p>
  
  <p>A user selects a black and white image for a scene. That image is drawn to the canvas and the pixel information is stored to an array - then hidden. I can then reference the array and see if my character is standing on a white pixel or a black pixel. This allows users to quickly draw their owns paths for scenes.</p>
  
  <p>I'm running into some trouble with my boundary detection though. While the character is walking, I'm checking boundaries at each step using this function (which returns true or false based on a white or black pixel):</p>
  
  <pre><code>inBounds:function(REF){
       var obj=$(this), 
       CH=obj.outerHeight(true), 
       CW=obj.outerWidth(true),
        L=obj.offset().left+(CW/2), 
        T=obj.offset().top+CH;
  
   return REF.pathData[(T * REF.sceneW + L)*4]&gt;200;
  }
  </code></pre>
  
  <p>The REF is my main object being used for REF throughout the script and REF.sceneW is the width of the canvas. The reference point is on the bottom/middle of the Character. </p>
  
  <p>I even created a little green dot to match the reference point so I can watch it while the character walks around the scene. Everything looks good and a boundary detection is recognized when the reference point hits the black/white line.</p>
  
  <p><img src="https://i.stack.imgur.com/VCM3H.jpg" alt="enter image description here"></p>
  
  <p>The problem happens when the character is standing on the black/white line and turns (shown above in the picture) - or with erratic movements. As soon as the reference point is in the black pixels (out of bounds)... it's game over. </p>
  
  <p>Perhaps someone can point out an issue with my boundary checking function or recommend a game coding technique to use to keep the character in bounds? Am I missing something?!</p>
  
  <p>Thanks!</p>
  
  <p><strong>UPDATE:</strong>
  I believe I have tracked the problem down to the step callback function inside the character animation. I'm using jQuery to do a few different things on the character during movement and the boundary detection is being called within the step callback... however this is called AFTER each step of the animation which is pushing the character into the black pixels - then calling the boundary detection. I believe this is the issue. Are there any workarounds?</p>