这比实际的工作代码更伪......
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;
};
然后我会遍历这个数组