gpt4 book ai didi

java - 在 libGDX 周围拖一个圈

转载 作者:行者123 更新时间:2023-11-30 01:05:21 25 4
gpt4 key购买 nike

我无法让一段 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
}
}

问题是如果手指移动得太快,圆盘就会停止移动。不知何故,圆盘的移动速度不够快,跟不上它看起来的运动。这有什么原因吗?

最佳答案

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

问题是,如果指针(鼠标或手指无关紧要)移动,您将不会获得它移动途中的每个位置,而只会得到一些点(移动得越快,得到的点越少) .指针比真正移动更“跳跃”。例如,如果用户引导画笔,图像编辑器只在这些点之间绘制线条,因此如果快速移动画笔,绘制的线条通常看起来更“有棱角”。

回到您的问题:在您最初检查用户想要拖动光盘后,设置一个 boolean 标志。当此标志为真时,将圆盘移动到指针所经过的每个位置,即使指针在圆盘之外。仅在释放指针时(onMouseUp 或其他)将此标志重置为 false。

所以你的代码看起来更像(伪代码)

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;
}

关于java - 在 libGDX 周围拖一个圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38910887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com