简体   繁体   English

检测手指何时离开屏幕并更新指针

[英]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种情况:

  1. Both disply sides are pressed -> move 两侧都按->移动
  2. Left display side pressed -> lean left 按下显示左侧->向左倾斜
  3. Right display side pressed -> lean right 向右按下显示侧->向右倾斜

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.

相关问题 如何在Android touchlistener中同时检测到触摸屏幕上的次要手指? - how to detect the secondary finger on touching the screen not at same time in android touchlistener? 知道视图何时在适配器中离开屏幕 - Know when a view leaves the screen in a Adapter 如何检测用户何时在JTabbedPane中离开某个选项卡 - How to detect when a user leaves a certain tab in a JTabbedPane 更新工作—如何通过在 android 的触摸屏上滑动手指来测试智能手机屏幕? - UPDATE WORKING— How to Test Smartphone Screen by swiping finger on the touch screen in android? 在 Android 上,当第一根手指从屏幕上松开时,如何判断第二根手指的位置,该手指没有移动但正在触摸屏幕 - On Android, how can I tell the location of a second finger that isn't moving but is touching the screen when the first finger releases from the screen 手指在屏幕上滑动的灵敏度 - The sensitivity of the finger swipe on the screen 检测何时显示安全锁 - Detect when security lock is on screen 让最后一根手指触摸屏幕 - Getting the last finger touching the screen Java工具提示:当鼠标光标从javafx表格视图中离开一行时,它不应停留在屏幕上 - Java Tooltip : it shouldn't stay on the screen when the mouse cursor leaves a row from a javafx tableview 检测用户何时在带有打印屏幕的Windows中拍摄屏幕截图? - Detect when user takes a screen shot in windows with print screen?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM