Cut rectangle with canvas in javascript?

I want to be able to hold mousedown on a rectangle, move in a direction, release, and after release have a rectangle "clicked" in the direction of the corresponding direction. I want to do something like this:

How do I click the DIV and make it move in the right direction?

but with a rectangle drawn in HTML5 canvas. How to achieve this?

+3
source share
1 answer

With the help of the canvas, you will want to use the same technique as in this post, except for using several frames and erasing / drawing a rectangle in each frame. Pseudocode:

setTimeout(1000/30, function () {
  canvas.erase()
  rect.update_position()
  canvas.drawRect(rect)
})

, Box2dWeb, , "flicking" - http://code.google.com/p/box2dweb/

+1

All Articles