gpt4 book ai didi

java - Libgdx Android 双触摸板问题

转载 作者:太空宇宙 更新时间:2023-11-04 15:20:51 27 4
gpt4 key购买 nike

我目前在使用两个触摸板时遇到问题,当使用“弹出”模式时,时不时会发生错误的触摸板被注册为触摸的情况。这意味着当我使用左侧触摸板时,有时会在触摸右侧触摸板时将其拾取,因此右侧触摸板的旋钮会移动到触摸板区域的最左侧。这种情况主要发生在两个手指“几乎”同时触摸屏幕时。我猜测我的代码中可能有错误,但我没有看到它。此外,此问题似乎仅在一个或两个触摸板处于 POPUP/INVISIBLE 模式时才会出现,因此这很可能是问题所在。

这是我程序的更新方法:

// MOVEMENT TOUCHPAD
switch(movementMode) {
case STATIC:
if(movementTouchpad.getKnobPercentX() != 0 || movementTouchpad.getKnobPercentY() != 0)
moveCamera();
break;
case POPUP:
case INVISIBLE:
if(Gdx.input.justTouched() && !movementTouchpad.isTouched()) {
// To prevent unwanted relocation of the touchpad
screenPosition.set(-1, -1);

// Store the position if the left half is touched
for(int i = 0; i < 10; i++) {
if(Gdx.input.isTouched(i)) {
if(Gdx.input.getX(i) < (screenWidth / 2.0f)) {
screenPosition.set(Gdx.input.getX(i), Gdx.input.getY(i));
break;
}
}
}

// See if the touchpad needs to be repositioned
if((screenPosition.x != -1) &&
(screenPosition.x > (touchpadWidth / 2)) &&
(screenPosition.x < ((screenWidth / 2) - (touchpadWidth / 2))) &&
(screenPosition.y > (touchpadHeight / 2)) &&
(screenPosition.y < (screenHeight - (touchpadHeight / 2)))) {
// Reposition the movement touchpad
movementTouchpad.setX(screenPosition.x - (touchpadWidth / 2));
movementTouchpad.setY((screenHeight - screenPosition.y) - (touchpadHeight / 2));
// Fire a fake touch event
stagePosition = movementStage.screenToStageCoordinates(screenPosition);
fakeTouchDownEvent.setStageX(stagePosition.x);
fakeTouchDownEvent.setStageY(stagePosition.y);
movementTouchpad.fire(fakeTouchDownEvent);
}
// Give feedback when touched too close to the border
else if(screenPosition.x != -1) {
switch(feedbackMode) {
case NONE:
break;
case SOUND:
//TODO
break;
case TACTILE:
Gdx.input.vibrate(VIBRATION_DURATION);
break;
case VISUAL:
//TODO
break;
}
}
}
if(movementTouchpad.getKnobPercentX() != 0 || movementTouchpad.getKnobPercentY() != 0)
moveCamera();
break;
}

// ROTATION TOUCHPAD
switch(rotationMode) {
case STATIC:
if(rotationTouchpad.getKnobPercentX() != 0 || rotationTouchpad.getKnobPercentY() != 0)
rotateCamera();
break;
case POPUP:
case INVISIBLE:
if(Gdx.input.justTouched() && !rotationTouchpad.isTouched()) {
// To prevent unwanted relocation of the touchpad
screenPosition.set(-1, -1);

// Store the position if the right half is touched
for(int i = 0; i < 10; i++) {
if(Gdx.input.isTouched(i)) {
if(Gdx.input.getX(i) > (screenWidth / 2.0f)) {
screenPosition.set(Gdx.input.getX(i), Gdx.input.getY(i));
break;
}
}
}

// See if the touchpad needs to be repositioned
if((screenPosition.x != -1) &&
(screenPosition.x > ((touchpadWidth / 2) + (screenWidth / 2))) &&
(screenPosition.x < (screenWidth - (touchpadWidth / 2))) &&
(screenPosition.y > (touchpadHeight / 2)) &&
(screenPosition.y < (screenHeight - (touchpadHeight / 2)))) {
// Reposition the rotation touchpad
rotationTouchpad.setX(screenPosition.x - (touchpadWidth / 2));
rotationTouchpad.setY((screenHeight - screenPosition.y) - (touchpadHeight / 2));
// Fire a fake touch event
stagePosition = movementStage.screenToStageCoordinates(screenPosition);
fakeTouchDownEvent.setStageX(stagePosition.x);
fakeTouchDownEvent.setStageY(stagePosition.y);
rotationTouchpad.fire(fakeTouchDownEvent);
}
// Give feedback when touched too close to the border
else if(screenPosition.x != -1) {
switch(feedbackMode) {
case NONE:
break;
case SOUND:
//TODO
break;
case TACTILE:
Gdx.input.vibrate(VIBRATION_DURATION);
break;
case VISUAL:
//TODO
break;
}
}
}
if(rotationTouchpad.getKnobPercentX() != 0 || rotationTouchpad.getKnobPercentY() != 0)
rotateCamera();
break;
}

任何帮助将不胜感激

最佳答案

这可能是因为您的手机可能完全支持多点触控,它可能只能进行触摸缩放,这种情况以前发生在我身上,因为我有 HTC 愿望,看看这个 video看看这是否是同一个问题。获取一个触摸屏应用程序,看看是否有相同的效果。

关于java - Libgdx Android 双触摸板问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20406255/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com