第一次在这里发帖,所以我希望可以让自己清楚。正如标题所述,我正在创建一个触摸板,它会在用户触摸设备屏幕的地方弹出。触摸板在前面创建并移动到触摸事件的 X、Y 坐标。现在实现的方式是,触摸板在移动后不会像被触摸一样,因为手指在触摸板位于该位置之前就在屏幕上。结果是您总是必须双击才能使用它(第一次点击移动它,第二次点击开始使用它)。有没有办法解决这个问题,例如在同一位置触发第二个“人工”触摸事件?如果可能,请提供代码示例。
这是我的重新定位代码:
if(popupMode) {
// Adjust the touchpad position when in popup mode
if(Gdx.input.isTouched()) {
// Assume at most 2 fingers touch the screen simultaneously
boolean left, right;
left = false;
right = false;
int x0, x1, y0, y1;
x0 = -1;
x1 = -1;
y0 = -1;
y1 = -1;
if(Gdx.input.isTouched(0)) {
x0 = Gdx.input.getX(0);
y0 = Gdx.input.getY(0);
if(x0 < (Gdx.graphics.getWidth() / 2.0f))
left = true;
else
right = true;
}
if(Gdx.input.isTouched(1)) {
x1 = Gdx.input.getX(1);
y1 = Gdx.input.getY(1);
if(x1 < (Gdx.graphics.getWidth() / 2.0f))
left = true;
else
right = true;
}
if(left) {
if(!repositionedMove) {
if( (x0 > -1) &&
(x0 > (touchpadMove.getWidth() / 2)) &&
(x0 < ((Gdx.graphics.getWidth() / 2) - (touchpadMove.getWidth() / 2))) &&
(y0 > (touchpadMove.getHeight() / 2)) &&
(y0 < (Gdx.graphics.getHeight() - (touchpadMove.getHeight() / 2)))) {
touchpadMove.setX(x0 - (touchpadMove.getWidth() / 2));
touchpadMove.setY((Gdx.graphics.getHeight() - y0) - (touchpadMove.getHeight() / 2));
touchpadMove.layout();
repositionedMove = true;
}
if( (x1 > -1) &&
(x1 > (touchpadMove.getWidth() / 2)) &&
(x1 < ((Gdx.graphics.getWidth() / 2) - (touchpadMove.getWidth() / 2))) &&
(y1 > (touchpadMove.getHeight() / 2)) &&
(y1 < (Gdx.graphics.getHeight() - (touchpadMove.getHeight() / 2)))) {
touchpadMove.setX(x1 - (touchpadMove.getWidth() / 2));
touchpadMove.setY((Gdx.graphics.getHeight() - y1) - (touchpadMove.getHeight() / 2));
touchpadMove.layout();
repositionedMove = true;
}
}
}
else
repositionedMove = false;
if(right) {
if(!repositionedRotate) {
if( (x0 > -1) &&
(x0 > ((touchpadRotate.getWidth() / 2) + (Gdx.graphics.getWidth() / 2))) &&
(x0 < (Gdx.graphics.getWidth() - (touchpadRotate.getWidth() / 2))) &&
(y0 > (touchpadRotate.getHeight() / 2)) &&
(y0 < (Gdx.graphics.getHeight() - (touchpadRotate.getHeight() / 2)))) {
touchpadRotate.setX(x0 - (touchpadRotate.getWidth() / 2));
touchpadRotate.setY((Gdx.graphics.getHeight() - y0) - (touchpadRotate.getHeight() / 2));
touchpadRotate.layout();
repositionedRotate = true;
}
if( (x1 > -1) &&
(x1 > ((touchpadRotate.getWidth() / 2) + (Gdx.graphics.getWidth() / 2))) &&
(x1 < (Gdx.graphics.getWidth() - (touchpadRotate.getWidth() / 2))) &&
(y1 > (touchpadRotate.getHeight() / 2)) &&
(y1 < (Gdx.graphics.getHeight() - (touchpadRotate.getHeight() / 2)))) {
touchpadRotate.setX(x1 - (touchpadRotate.getWidth() / 2));
touchpadRotate.setY((Gdx.graphics.getHeight() - y1) - (touchpadRotate.getHeight() / 2));
touchpadRotate.layout();
repositionedRotate = true;
}
}
}
else
repositionedRotate = false;
}
else {
repositionedMove = false;
repositionedRotate = false;
}
}