0
我一直在試圖找到/創建在Libgdx的矩形碰撞檢測,但我似乎無法得到任何地方。我有一個長方形,稱爲桶,寬64高,長方形稱爲牆,寬64高。我試圖讓玩家不穿過矩形,可以繼續移動,同時堅持牆逐步或隨機傳送。我的方法工作時,有1塊,但是當有多個,它只是打破,不工作。Libgdx矩形牆碰撞
我知道這個方法是醜陋的,但它只是試驗
private void checkCollisions(Rectangle bucket, Wall wall){
if(bucket.overlaps(wall.getRectangle())){
if(bucket.x > wall.getRectangle().x - 64 && bucket.x < wall.getRectangle().x - 55){
//collision with right side
bucket.x = wall.getRectangle().x - 64;
}
if(bucket.x < wall.getRectangle().x + 64 && bucket.x > wall.getRectangle().x + 55){
//collision with left side
bucket.x = wall.getRectangle().y + 64;
}
if(bucket.y < wall.getRectangle().y + 64 && bucket.y > wall.getRectangle().y + 55){
//collision with top side
bucket.y = wall.getRectangle().y + 64;
}
if(bucket.y > wall.getRectangle().y - 64 && bucket.y < wall.getRectangle().y - 55){
//collision with bottom side
bucket.y = wall.getRectangle().y - 64;
}
}
}
,我會很感激,如果有人可以點我在正確的方向或分享一些代碼,會幫助我。