Java 用屏幕坐标计算等轴测游戏中数组的位置

Java 用屏幕坐标计算等轴测游戏中数组的位置,java,arrays,coordinates,isometric,Java,Arrays,Coordinates,Isometric,我正在使用site用java制作一个非常基本的等距游戏,只是它用来将屏幕坐标转换为数组中的位置的方法不起作用 这是我用来将屏幕坐标转换为阵列位置的: public void GetMouseInArray(){ int[] pos = new int[2]; pos[0] = window.getMousePosition().x; pos[1] = window.getMousePosition(). pos = CalcCarPos(pos);

我正在使用site用java制作一个非常基本的等距游戏,只是它用来将屏幕坐标转换为数组中的位置的方法不起作用

这是我用来将屏幕坐标转换为阵列位置的:

public void GetMouseInArray(){
    int[] pos = new int[2];

    pos[0] = window.getMousePosition().x;
    pos[1] = window.getMousePosition().

    pos = CalcCarPos(pos);

    int[] temppos = new int[2];
    temppos[0] = (int) Math.floor(pos[0]/80);
    temppos[1] = (int) Math.floor(pos[1]/80);
    pos = temppos;
}
这是CalcCarPos函数:

private int[] CalcCarPos(int[] pos){
    int[] temppos = new int[2];
    temppos[0] = (2*pos[1]+pos[0])/2;
    temppos[1] = (2*pos[1]-pos[0])/2;
    return temppos;
}
我使用几乎相同的代码在屏幕上绘制阵列,我的分幅是80x80像素。我做错了什么

temppos[0] = (2*pos[1]+pos[0])/2;
temppos[1] = (2*pos[1]-pos[0])/2;
这是你想要的吗?这意味着将pos[1]乘以2,将pos[0]与结果相加,然后将其除以2。还是将pos[1]和pos[0]之和乘以2

temppos[0] = (2*(pos[1]+pos[0]))/2;
temppos[1] = (2*(pos[1]-pos[0]))/2;

建议使用a来存储坐标,因为它比
int[]稍微干净一些。
您如何知道它不起作用?谢谢,我将所有int都改为Point。我知道它不起作用,因为我将屏幕标题更改为转换后的位置。“更改屏幕标题”这样您就创建了一个窗口并正在测试其中的代码?代码请同时包括您正在测试的代码?假设我选择了X:165,Y:165。是否要返回数组位置1,1?对的