保存 libgdx
Save touches on libgdx
是否可以在渲染时保存第一次触摸、释放然后读取第二次或新触摸libgdx?我只找到这个 Gdx.input.isTouched (int) 而 int 是同时有多少手指的索引,但我需要先释放然后再触摸。
如果这个问题以前回答过,在哪里?
我假设你想保护触摸坐标?
Gdx.justTouched
只会 运行 一次,直到发布。或者您可以实现 GestureListener
并使用它的 tap(int x, int y, int button)
方法。
因此,只要在检测到触摸时存储 Gdx.input.getX
和 Gdx.input.getY
,并且您会保存这些,直到您再次保存下一次触摸。
您可以创建自己的 InputProcessor 并通过以下方式覆盖您的 touchDown 和 touchUp 事件:
声明您的触摸 hashmap:
private Map<Integer,TouchInfo> touches = new HashMap<Integer,TouchInfo>();
touchDown 事件:
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if(touches.get(pointer) == null){
touches.put(pointer, new TouchInfo());
}
touches.get(pointer).touchX = screenX;
touches.get(pointer).touchY = screenY;
touches.get(pointer).touched = true;
return true;
}
和 touchUp 事件:
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
touches.get(pointer).touchX = 0;
touches.get(pointer).touchY = 0;
touches.get(pointer).touched = false;
return true;
}
TouchInfo class:
class TouchInfo {
public float touchX = 0;
public float touchY = 0;
public boolean touched = false;
}
您可以处理设备支持的触摸次数,或者如果您愿意,可以根据需要限制输入。
是否可以在渲染时保存第一次触摸、释放然后读取第二次或新触摸libgdx?我只找到这个 Gdx.input.isTouched (int) 而 int 是同时有多少手指的索引,但我需要先释放然后再触摸。
如果这个问题以前回答过,在哪里?
我假设你想保护触摸坐标?
Gdx.justTouched
只会 运行 一次,直到发布。或者您可以实现 GestureListener
并使用它的 tap(int x, int y, int button)
方法。
因此,只要在检测到触摸时存储 Gdx.input.getX
和 Gdx.input.getY
,并且您会保存这些,直到您再次保存下一次触摸。
您可以创建自己的 InputProcessor 并通过以下方式覆盖您的 touchDown 和 touchUp 事件:
声明您的触摸 hashmap:
private Map<Integer,TouchInfo> touches = new HashMap<Integer,TouchInfo>();
touchDown 事件:
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if(touches.get(pointer) == null){
touches.put(pointer, new TouchInfo());
}
touches.get(pointer).touchX = screenX;
touches.get(pointer).touchY = screenY;
touches.get(pointer).touched = true;
return true;
}
和 touchUp 事件:
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
touches.get(pointer).touchX = 0;
touches.get(pointer).touchY = 0;
touches.get(pointer).touched = false;
return true;
}
TouchInfo class:
class TouchInfo {
public float touchX = 0;
public float touchY = 0;
public boolean touched = false;
}
您可以处理设备支持的触摸次数,或者如果您愿意,可以根据需要限制输入。