Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.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 - Fatal编程技术网

Java 围绕libGDX拖动一个圆

Java 围绕libGDX拖动一个圆,java,android,libgdx,Java,Android,Libgdx,我很难让一段libGDX代码正常工作 if(Gdx.input.isTouched()) { setTouchPos(); //set the x and y values of current touch cam.unproject(touchPos); if(disc.contains(touchPos.x, touchPos.y)) { disc.x = touchPos.x - disc.radius / 2

我很难让一段libGDX代码正常工作

if(Gdx.input.isTouched()) {
        setTouchPos();    //set the x and y values of current touch
        cam.unproject(touchPos);

        if(disc.contains(touchPos.x, touchPos.y)) {
            disc.x = touchPos.x - disc.radius / 2; // disc.x becomes current touch position
            disc.y = touchPos.y - disc.radius / 2; // disc.y becomes current touch position
        }
    }

问题是,如果手指移动过快,光盘将停止移动。不知何故,光盘的转换速度不够快,无法跟上它看起来的移动。有什么原因吗?

从您的代码中,我猜您试图做的是用指针(手指)拖动光盘,您可以通过检查指针是否在光盘中来实现这一点

问题是,如果指针(不管是鼠标还是手指)移动,你不会得到它移动过程中的每个位置,只会得到一些点(移动得越快,得到的点就越少)。指针更多的是“跳跃”,而不是真正移动。例如,如果用户引导画笔,图像编辑器只在这些点之间绘制线条,因此如果画笔快速移动,绘制的线条看起来更“有角度”

回到您的问题:在您最初检查用户是否希望拖动光盘后,设置一个布尔标志。当此标志为真时,将光盘移动到指针移动的每个位置,即使指针位于光盘外部。仅在释放指针(onMouseUp或其他)时将此标志重置为false

因此,您的代码看起来更像(伪代码


+他的方法是正确的。我还建议看一看我会+1你,但我不能,谢谢你@Sebastian的帮助和信息丰富的回答。我现在正在努力实施!
if (disc.contains(touchPos.x, touchPos.y)) {
    dragged = true;
}

...

if (dragged) {
    disc.x = touchPos.x - disc.radius / 2; // disc.x becomes current touch position
    disc.y = touchPos.y - disc.radius / 2; // disc.y becomes current touch position
}

...

public onMouseUp() {
     dragged = false;
}