Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java libgdx多个pan事件_Java_Android_Libgdx - Fatal编程技术网

Java libgdx多个pan事件

Java libgdx多个pan事件,java,android,libgdx,Java,Android,Libgdx,在我的游戏中,用户应该用屏幕左侧的一个手指移动玩家,并且可以用右手手指射击。问题是当投篮时,球员不能再移动了。我发现了一些相关的问题,但没有一个对我有帮助。我尝试了使用两个不同的GestureListener类。其中一个检查屏幕的右侧是否被触摸,另一个检查左侧是否仍不工作 这是第一类的pan方法 public boolean pan(float x, float y, float deltaX, float deltaY) { lastTouch = new Vector

在我的游戏中,用户应该用屏幕左侧的一个手指移动玩家,并且可以用右手手指射击。问题是当投篮时,球员不能再移动了。我发现了一些相关的问题,但没有一个对我有帮助。我尝试了使用两个不同的GestureListener类。其中一个检查屏幕的右侧是否被触摸,另一个检查左侧是否仍不工作

这是第一类的pan方法

    public boolean pan(float x, float y, float deltaX, float deltaY) {
        lastTouch = new Vector2(x, y).sub(deltaX, deltaY);
        Vector2 newTouch = new Vector2(x, y);

        Vector2 delta = newTouch.cpy().sub(lastTouch);
        if(lastTouch.x < Gdx.graphics.getWidth()/2 && newTouch.x < Gdx.graphics.getWidth()/2) {
            stage.getPlayer().move(new Vector2(delta.x, -delta.y));
        }
        lastTouch = newTouch;
        return true;
    }

谢谢

LibGDX中的侦听器倾向于使用布尔返回值来说明输入是否已完成处理。当您返回true时,侦听器停止处理进一步的操作

GestureListener可以通过从其方法中分别返回true或false来表示它是否使用了事件或希望将其传递给下一个InputProcessor


尝试将return方法更改为false,看看这是否解决了问题,否则尝试将其转换为使用触地和触地方法,该方法具有用于手指计数的参数指针。当您返回true时,侦听器停止处理进一步的操作

GestureListener可以通过从其方法中分别返回true或false来表示它是否使用了事件或希望将其传递给下一个InputProcessor


尝试将返回方法更改为false,看看这是否解决了问题,否则尝试将其转换为使用触地和触地方法,该方法具有手指计数的参数指针

否它没有解决问题可能是pan方法仅适用于单个手指。您可以尝试将其转换为使用触地和触地方法,该方法有一个用于手指计数的参数指针。不,它没有解决这一问题,可能是pan方法仅适用于单个手指。您可以尝试将其转换为使用触地和触地方法,该方法具有用于手指计数的参数指针。
    public boolean pan(float x, float y, float deltaX, float deltaY) {
        lastTouch = new Vector2(x, y).sub(deltaX, deltaY);
        Vector2 newTouch = new Vector2(x, y);

        Vector2 delta = newTouch.cpy().sub(lastTouch);
        if(lastTouch.x > Gdx.graphics.getWidth()/2 && newTouch.x > Gdx.graphics.getWidth()/2){
            if(shoot) {
                bullets.add(new Bullet(WorldUtils.createBullet(stage.getWorld(), stage.getPlayer().getBody().getPosition().x+70, stage.getPlayer().getBody().getPosition().y, new Vector2(delta.x, -delta.y)), new Vector2(delta.x, -delta.y)));
                shoot = false;
            }
            stage.getPlayer().turn(new Vector2(delta.x, -delta.y));
        }
        lastTouch = newTouch;
        return true;
    }