我正在用java创建一个2D平台游戏,我想添加一个滚动的敌人。为此,我必须旋转getBounds矩形和代表敌人的图像。有什么方法可以做到这一点,仍然可以使用旋转的矩形进行矩形碰撞检测?我一直在看别人的帖子,但他们正在创建一个新的形状,我想要一个旋转的矩形,而不是一个新的形状。我想用它来进行矩形碰撞检测:
public void collision(LinkedList<GameObject> object){
for(int i = 0; i < handler.object.size(); i++){
GameObject tempObject = handler.object.get(i);
if(tempObject.getID() == ID.RollingEnemy){
if(getBounds().intersects(tempObject.getBounds())){
//collided with rolling at players bottom
}
if(getBoundsTop().intersects(tempObject.getBounds())){
//collided with rolling at players top
}
if(getBoundsLeft().intersects(tempObject.getBounds())){
//collided with rolling at players left
}
if(getBoundsRight().intersects(tempObject.getBounds())){
//collided with rolling at players right
}
}
}
}
请帮忙!