我正在使用Libgdx的数组来存储我自己的' Coordinate'类。在另一个类中,我正在引用该数组,以查看是否存在"块"在玩家的视线中。我已经完成了所有的线编程,但我似乎无法找出如何查看数组是否包含一个' Coordinate'就像我拥有的那个临时的。我似乎已经开始使用它了
if(hex.getWorld().get(0).equals(tmp)) {
System.out.println("break");
break;
}
但这仅适用于其中一个“坐标”。我希望它可以与所有协调员合作。虽然看起来它会起作用,但它并没有:
if(hex.getWorld().contains(tmp, true)) {
System.out.println("break");
break;
}
(如果这不是有效的代码,请注意它没有被复制,我现在手写了) 这是我在该地区使用的代码。
....
tmp = new Coordinate();
for(int i = 1; i <= 5; i++){
tmp.setX(Math.round((cam.direction.x * i) + cam.position.x));
tmp.setY(Math.round(((cam.direction.y * i) + cam.position.y) / 0.578f));
tmp.setZ(Math.round((cam.direction.z * i) + cam.position.z));
//System.out.println(tmp.toString(false));
//System.out.println(hex.getWorld().get(0).toString(false) + " - " + tmp.toString(false));
System.out.println(hex.getWorld().contains(tmp, true));
if(hex.getWorld().contains(tmp, false)){
System.out.println("break");
break;
}
}
//////////// BE-OND THIS POINT THE CODE IS CORRECT ////////////
float slope = (cam.direction.z) / (cam.direction.x);
if(spot != tmp){
hex.instances.removeIndex(hex.instances.indexOf(i, true));
spot = tmp;
float size = 0.578f;
float x = spot.getFormatedX(spot);
float y = (spot.getY() * size);
float z = spot.getFormatedZ(spot);
i = new ModelInstance(hex.getHex("red"), x, y, z);
i.transform.scale(size, size, size);
hex.instances.add(i);
}
....
这是在每个游戏循环中运行,我知道我应该在我的相机控制器的mouseMoved()
功能中使用它。 hex
变量也是一个自定义类,但它与Array
下的hex.getWorld()
无关。数组在类中设置如下:
Array<Coordinate> world = new Array<Coordinate>();
答案 0 :(得分:0)
我意识到我的equals()
课程中的Coordinate
函数已经进入
equals(Coordinate coord){
代替equals(Object cord){
。这使它发挥作用。
感谢@ Tenfour04,评论Did you write a proper .equals method for your Coordinate class?
!