HTML5 Canvas圆与矩形之间的碰撞

时间:2012-12-04 22:36:32

标签: javascript html5 canvas html5-canvas

  

可能重复:
  Circle-Rectangle collision detection (intersection)
  Collision detection between a line and a circle in JavaScript

这比实际工作代码更伪...

var dX = rectanlge.x - circle.x;
var dY = rectangle.y - circle.y;
var distance = Math.sqrt((dX*dX)+(dY*dY));
if(distance < circle.radius){
     //Collision
}

到目前为止,这是检测圆形和矩形是否在画布动画中发生碰撞的全部内容。我显然错了,有人可以指出我正确的方向吗?

rectangles = [];    
var rectangle = function(x,y,width,height){
            this.x = x;
            this.y = y;
            this.width = width;
            this.height = height;
        };

然后我会遍历这个数组

1 个答案:

答案 0 :(得分:2)