(编辑)没关系...... 如果(r.overlaps(b.getBounds())); 应该读 如果(r.overlaps(b.getBounds()))
<!/ P>
我正在尝试使用libgdx检查两个矩形的重叠,并且该函数返回true,除非我完全丢失了绘图,否则根本没有重叠:
for(Block b:this.collidableBlocks)
{
if(b==null) continue;
Rectangle r = Bullet.this.getBounds();
if(r.overlaps(b.getBounds()));
{
Bullet.this.destroy();
break;
}
}
当我打破调试器时,r的界限是: x = 174.0 y = 30.25068 w = 0.3 h = 0.05
并且b的界限是: x = 0 y = 0 w = 1 h = 1
是的.overlaps()函数返回true
.overlaps()的代码如下:
public boolean overlaps (Rectangle r) {
return x < r.x + r.width && x + width > r.x && y < r.y + r.height && y + height > r.y;
}
答案 0 :(得分:0)
没关系......它有点大脑褪色...... if语句以半冒号结束:$
//this
if(r.overlaps(b.getBounds()));
//should say
if(r.overlaps(b.getBounds()))