Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.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手势检测仅单向滚动_Java_Android_Libgdx_Gesturedetector - Fatal编程技术网

Java 如何使用Libgdx手势检测仅单向滚动

Java 如何使用Libgdx手势检测仅单向滚动,java,android,libgdx,gesturedetector,Java,Android,Libgdx,Gesturedetector,我已经制作了一个简单的游戏,主要元素是向上滚动背景。但是,我不知道如何使应用程序只能单向滚动。背景不能向下滚动。y是在背景中滚动的摄影机 下面是我的代码的样子: import com.badlogic.gdx.Gdx; import com.badlogic.gdx.input.GestureDetector.GestureListener; import com.badlogic.gdx.math.Vector2; import com.vahlaville.game.screens.Worl

我已经制作了一个简单的游戏,主要元素是向上滚动背景。但是,我不知道如何使应用程序只能单向滚动。背景不能向下滚动。y是在背景中滚动的摄影机

下面是我的代码的样子:

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.input.GestureDetector.GestureListener;
import com.badlogic.gdx.math.Vector2;
import com.vahlaville.game.screens.WorldScreen;

public class GestureListenerC implements GestureListener{

public static float velX, velY;
public static boolean flinging = false;
float initialScale = 1;

public boolean touchDown (float x, float y, int pointer, int button) {
    flinging = false;
    initialScale = WorldScreen.camera.zoom;
    return false;
}

@Override
public boolean tap (float x, float y, int count, int button) {
    //Gdx.app.log("GestureDetectorTest", "tap at " + x + ", " + y + ", count: " + count);
    return false;
}

@Override
public boolean longPress (float x, float y) {
    //Gdx.app.log("GestureDetectorTest", "long press at " + x + ", " + y);
    return false;
}

@Override
public boolean fling (float velocityX, float velocityY, int button) {
    //Gdx.app.log("GestureDetectorTest", "fling " + velocityX + ", " + velocityY);
    flinging = true;
    velX = WorldScreen.camera.zoom * velocityX * 0.5f;
    velY = WorldScreen.camera.zoom * velocityY * 0.5f;
    if(WorldScreen.value <= 0)WorldScreen.value = 0;
    return false;
}

@Override
public boolean pan (float x, float y, float deltaX, float deltaY) {
    // Gdx.app.log("GestureDetectorTest", "pan at " + x + ", " + y);
        if(!WorldScreen.ending){
    if(WorldScreen.value != 0){
        WorldScreen.camera.position.add(0, Math.abs(deltaY * WorldScreen.camera.zoom), 0);
        WorldScreen.value -= Math.abs(1 * deltaY);
    }
    if(WorldScreen.camera.position.y <= 0) WorldScreen.camera.position.y = 0;
        }
    if(WorldScreen.value <= 0)WorldScreen.value = 0;
    return false;
}

@Override
public boolean panStop (float x, float y, int pointer, int button) {
    //Gdx.app.log("GestureDetectorTest", "pan stop at " + x + ", " + y);
    return false;
}

@Override
public boolean zoom (float originalDistance, float currentDistance) {

    return false;
}

@Override
public boolean pinch (Vector2 initialFirstPointer, Vector2 initialSecondPointer, Vector2 firstPointer, Vector2 secondPointer) {
    return false;
}

public void update () {
        if(!WorldScreen.ending){
    if (flinging) {

        if(WorldScreen.value != 0){
            velY *= 0.98f;
            WorldScreen.value -= 1.5f * velY;
            WorldScreen.camera.position.add(0, velY * Gdx.graphics.getDeltaTime(), 0);
            if (Math.abs(velY) < 0.01f) velY = 0;
        }
        if(WorldScreen.camera.position.y <= 480){ WorldScreen.camera.position.y = 480; WorldScreen.value = 384400000;}
    }
        }
    if(WorldScreen.value <= 0)WorldScreen.value = 0;
}
导入com.badlogic.gdx.gdx;
导入com.badlogic.gdx.input.GestureDetector.GestureListener;
导入com.badlogic.gdx.math.Vector2;
导入com.vahlaville.game.screens.WorldScreen;
公共类GestureListenerC实现GestureListener{
公共静态浮动velX,velY;
公共静态布尔抛出=false;
浮动初始刻度=1;
公共布尔接地(浮点x、浮点y、整数指针、整数按钮){
投掷=假;
initialScale=WorldScreen.camera.zoom;
返回false;
}
@凌驾
公共布尔点击(浮点x、浮点y、整数计数、整数按钮){
//Gdx.app.log(“GestureDetectorTest”,“点击“+x+”,“+y+”,计数:“+count”);
返回false;
}
@凌驾
公共布尔长按(浮点x,浮点y){
//Gdx.app.log(“GestureDetectorTest”,“长按“+x+”,“+y”);
返回false;
}
@凌驾
公共布尔触发器(float-velocityX、float-velocityY、int按钮){
//Gdx.app.log(“GestureDetectorTest”、“fling”+velocityX+”、“+velocityY”);
投掷=正确;
velX=WorldScreen.camera.zoom*velocityX*0.5f;
velY=WorldScreen.camera.zoom*velocityY*0.5f;

如果(WorldScreen.value)在deltaY为负片时不让相机平移如何?这对我解决了这个问题!谢谢!