【发布时间】:2016-01-08 00:13:06
【问题描述】:
我正在使用 Libgdx 的数组来存储我自己的“坐标”类。在另一个类中,我正在参考该数组,以查看玩家的视线中是否存在“障碍”。我已经完成了所有的线路编程,但我似乎无法找出如何查看数组是否包含一个“坐标”,就像我拥有的临时坐标一样。我似乎已经开始使用它了
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 变量也是一个自定义类,但它与hex.getWorld() 下的Array 无关。并且数组在类中是这样设置的:
Array<Coordinate> world = new Array<Coordinate>();
【问题讨论】:
-
您是否为您的 Coordinate 类编写了正确的 .equals 方法?
-
我用了一个...让我检查一下...