0
(編輯)沒關係... if(r.overlaps(b.getBounds())); 應該讀 如果(r.overlaps(b.getBounds()))矩形重疊代碼不按預期工作(當沒有重疊時返回true)
!
我試圖檢查使用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()函數用於.overlaps返回true
()的代碼如下:
public boolean overlaps (Rectangle r) {
return x < r.x + r.width && x + width > r.x && y < r.y + r.height && y + height > r.y;
}
如果申報值是正確的,這是很明顯的,功能.overlaps(矩形)應該返回false,因爲在返回狀態第一個組件(x
沒關係...這是一個大腦褪色... if語句以分號結束:$ – LairdPleng
Oooohhh ...我覺得你:D「缺少逗號」錯誤:)不管怎樣,好運氣! –