特别是,我试图通过触地得分方法首先确定触摸是在屏幕的左侧还是右侧。屏幕方法我认为屏幕的宽度为136像素,但我的代码似乎将屏幕宽度的1/4解释为左键。
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
touchX=screenX;
touchY=screenY;
if(screenX<= 136/2) {
myToken.onLeftClick();
}else{
myToken.onRightClick();
}
return true;
}
答案 0 :(得分:1)
您需要使用camera.unproject来获取世界坐标。
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
Vector3 vec=new Vector3(screenX,screenY,0);
camera.unproject(vec);
touchX=vec.x;
touchY=vec.y;
if(screenX<= 136/2) {
myToken.onLeftClick();
}else{
myToken.onRightClick();
}
return true;
}