0
我想提出一个游戏,我已存储的INT数组INT整数三维地图的坐标:如何获得线性阵列
int width = 256;
int height = 256;
int depth = 64;
int[] map = new int[width * height * depth];
我需要能够得到获得X,Y,索引的z。我想出了目前的方法是:
private int getX(int blockID) {
return blockID % width;
}
private int getY(int blockID) {
return (blockID % depth)/height;
}
private int getDepth(int blockID) {
return blockID/(width * height);
}
用于获取x和深度的方法似乎工作,但我不能得到的getY()正常工作,我不断收到和ArrayIndexOutOfBoundsException异常类似下面:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at game.Level.updateLighting(Level.java:98)
at game.Level.generateMap(Level.java:58)
at game.Level.<init>(Level.java:21)
at game.mainClass.main(Minecraft.java:6)
请帮助,如果你知道如何做到这一点。
+1 “哥们”;也为一个很好的答案;) – WaelJ
其效率不高 –
@stas谨慎详细说明?在什么方面,一个一维阵列的'w * h * d'元素比一个等效的三维阵列“效率更高”? –