[英]detect when a finger leaves the screen and update pointers
I'm making a game where I accelerate holding two fingers on the screen , a finger in the left half and a finger in the right half of the display . 我正在做一个游戏,加速按住屏幕上的两只手指,手指放在显示屏的左半边。 if you release your finger and let down the other , whatever it is I have to bend the vehicle based on the location of the finger .
如果您松开手指并放下另一根手指,无论我要做什么,我都要根据手指的位置弯曲车辆。 If you are located in the right half ( Gdx.grapchis.getWidth / 2 ) then I bend to the right ... and so the left .
如果您位于右半部分(Gdx.grapchis.getWidth / 2),那么我会向右弯曲...然后向左弯曲。
part of input processor: 输入处理器的一部分:
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if(pointer < 2)
{
CoordinateTouch tmp = new CoordinateTouch();
tmp.x = screenX;
tmp.y = screenY;
coordinates.add(tmp);
}
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
coordinates.clear();
return false;
}
my array of coordinates: 我的座标数组:
public class CoordinateTouch{
float x;
float y;
}
List<CoordinateTouch> coordinates;
control pointer in render method (group is my texture): 渲染方法中的控制指针(组是我的纹理):
if(coordinates.size() > 1)
{
group.addAction(parallel(moveTo(realDest.x, realDest.y, (float) 15)));
}
else
{
group.addAction(delay((float)1.5));
group.clearActions();
if(Gdx.input.isButtonPressed(0)) {
if (Gdx.input.getX() < Gdx.graphics.getWidth() / 2) {
group.addAction(parallel(rotateBy(velocityRotazionShip, (float) 0.03)));
} else {
group.addAction(parallel(rotateBy(-velocityRotazionShip, (float) 0.03)));
}
}
}
My problem is that if I leave one finger detects it , and so far so good , but if I just leaned back his finger pulled away, I do not update the pointers and did not produce the piece of code group.addAction . 我的问题是,如果我让一根手指检测到它,并且到目前为止还算不错,但是如果我只是将手指向后拉开,我就不会更新指针,也不会产生代码段group.addAction。
I also tried isButtonPressed and isKeypressed, isTouched(index) , but the result is the same. 我也尝试过isButtonPressed和isKeypressed,isTouched(index),但是结果是一样的。
Sorry for the English and I hope to have been clear . 对不起英语,我希望情况清楚。
If i understood you corectly you have 3 cases: 如果我从根本上理解您,那么您有3种情况:
If that assumption is correct, you would only need to boolean
s: 如果该假设正确,则只需要
boolean
s即可:
boolean touchLeft, touchRight
Inside the touchDown
you could do something like that: 在
touchDown
内,您可以执行以下操作:
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if (screenX < Gdx.graphics.getWidth()/2)
touchLeft = true;
else
touchRight = true;
}
And in the touchUp
: 并在
touchUp
:
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
if (screenX < Gdx.graphics.getWidth()/2)
touchLeft = false;
else
touchRight = false;
}
Now inside the render
you can just say: 现在在
render
您可以说:
if (touchLeft && touchRight)
// move
else if (touchLeft)
// lean left
else if (touchRight)
// leanRight
else
// do nothing or something else
If you want to support multiple fingers/side, you can change the boolean
s to int
s, giving the number of fingers/side. 如果要支持多个手指/侧面,可以将
boolean
s更改为int
,以提供手指/侧面的数量。 In the touchDown
increment it, in the touchUp
decrement it and in the render ask, if it is > 0. 在
touchDown
递增,在touchUp
递减,在渲染询问中,它是否大于0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.