我有一个碰撞方法是用矩形完成的。当我的玩家与我制作的牌public Rectangle getBounds() { //Bottom bounds
return new Rectangle(((int) x + (width /2 ) - (width / 2)/2), ((int) y + (height / 2) ), width / 2 , (height / 2) );
}
发生碰撞(Intercepts)时,当我在游戏中时,它会打印出真实的,有时是假的。我已经坚持这个问题好几个小时了,感谢你的帮助。
以下是代码:
播放器的底部矩形
public Rectangle getBounds() {
return new Rectangle((int)x, (int) y, 32, 32);
}
对于瓷砖:
private int width = 30;
private int height = 40;
if (tempObject.getObjectID() != ObjectsList.Player ) {
if (getBounds().intersects(tempObject.getBounds()) || tempObject.getBounds().intersects(getBounds())) { // If the player bottom bounds collides with object bounds
velY = 0;
falling = false;
jumping = false;
y = tempObject.getY() - (height);
} else {
System.out.println(falling);
falling = true;
}
}
检测碰撞:
{{1}}
谢谢,
NattoShaw