【发布时间】:2013-11-20 19:40:14
【问题描述】:
我正在使用this 站点在 java 中制作一个非常基本的 Isometric 游戏,只有它用于将屏幕坐标转换为数组中的位置的方法不起作用。
这是我用来将屏幕坐标转换为数组位置的方法:
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 像素。我在这里做错了什么?
【问题讨论】:
-
建议使用
java.awt.Point来存储坐标,因为它比int[]稍微干净一些 -
你怎么知道它不起作用?
-
谢谢,我把所有的整数都改成了点。我知道它不起作用,因为我将屏幕标题更改为转换后的位置。
-
"更改屏幕标题" 这样您就创建了一个窗口并正在测试其中的代码?代码你也请包括你正在测试它的代码?
标签: java arrays coordinates isometric