我正在嘗試爲老派RPG編寫一張碰撞圖。我使用紅色(255,0,0)創建了一個圖像,其中碰撞應該發生,並且試圖測試我的精靈位置(x,y)何時會在碰撞圖上變爲紅色。這裏是我的代碼,將似乎沒有工作:紅色測試
public boolean isBlocked(int testX, int testY) {
System.out.println(collisionMap.getColor(testX, testY)); //debug
System.out.println(Color.red); //debug
if ((collisionMap.getColor(testX, testY)) == Color.red) {
System.out.println("COLLISION OCCURRING!"); //debug
return true;
}
else {
System.out.println("NO COLLISION OCCURRING!"); //debug
return false;
}
}
當碰撞應該發生的,我得到了我的控制檯輸出如下:
顏色(1.0,0.0,0.0,1.0)
顏色(1.0,0.0,0.0,1.0)
無碰撞發生!
由於某些原因,If語句沒有將兩個值相提並論,即使它們似乎是。
他們不枚舉,使用.equals() – esej