我一直在寫一個遊戲引擎,我的演員類有問題。我想確定一個矩形(上圖)和矩形的一邊的碰撞。我爲他們寫了兩種方法。Java遊戲碰撞檢測,(側面碰撞)與矩形
public boolean isLeftCollision(Actor actor) {
boolean bool = false;
Rectangle LeftBounds = new Rectangle(x, y, x-velocity, image.getHeight(null));
bool = LeftBounds.intersects(actor.getBounds());
return bool;
}
public boolean isRightCollision(Actor actor) {
boolean bool = false;
Rectangle RightBounds = new Rectangle(x+image.getWidth(null), y, image.getWidth(null)+velocity, image.getHeight(null));
bool = RightBounds.intersects(actor.getBounds());
return bool;
}
這裏速度是下一步的運動。
但他們都給我錯誤(即錯誤的判斷)。我該如何在演員課上解決這個問題。
添加錯誤日誌 – 2012-01-15 00:06:08
@stas如何添加錯誤日誌 – 2012-01-15 00:13:15
lol。運行該程序並複製並粘貼該錯誤。 – 2012-01-15 00:15:57