layabox 2D 怎么样判断图片碰撞?

图片一般是正方形,x、y坐标一般都是左上角,所以碰撞公式一般为

// hitRange 碰撞距离
if(Math.abs(shootball.x-ball.x) < hitRange && Math.abs(shootball.y-ball.y)

或者

   if(MathUtils.distance(shootball.x,shootball.y,ball.x,ball.y)< hitRange)
   {  
  	 trace("碰撞了");
   }
	
/**
 * 计算距离
 * @param	x1	点1的x坐标
 * @param	y1	点1的y坐标
 * @param	x2	点2的x坐标
 * @param	y2	点2的y坐标
 * @return	2点之间的距离
 */
public static function distance(x1:Number, y1:Number, x2:Number, y2:Number):Number
{
	return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}

你可能感兴趣的:(技术支持)