简体   繁体   English

Libgdx检测水平滚动

[英]Libgdx Detect horizontal scrolling

I'm working on a desktop only project using the libgdx game library, and I'm looking to implement a way for when the user scrolls horizontally to pan the camera. 我正在使用libgdx游戏库在仅限桌面的项目上工作,并且我正在寻求实现一种当用户水平滚动以平移相机时的方法。 I'd like to avoid using libgdx's scene2d if possible. 如果可能的话,我想避免使用libgdx的scene2d。 However, I can't see to find a way to capture horizontal scrolls. 但是,我看不到找到捕获水平滚动的方法。 Is there anyway to detect a horizontal mouse scroll in Libgdx? 无论如何,在Libgdx中是否检测到水平鼠标滚动? I'd like to avoid using libgdx's scene2d if possible. 如果可能的话,我想避免使用libgdx的scene2d。 And if there is not, is there a way to do it using plain java, without using awt, swing, or javafx? 如果没有,有没有办法使用纯Java而不使用awt,swing或javafx?

Horizontal mouse scrolls? 水平滚动鼠标? There is no such thing unless you are using a mouse with multiple scroll wheels. 除非您使用带有多个滚轮的鼠标,否则不会发生任何事情。 Usually the mouse has one scroll wheel. 通常,鼠标只有一个滚轮。

However, if you mean moving the mouse horizontally, you should be able to capture that using getDeltaX() . 但是,如果要水平移动鼠标,则应该能够使用getDeltaX()捕获鼠标。 Note that it's a raw input, so you will want to divide it by the screen's width in order to make movement the same on any monitor you use. 请注意,这是原始输入,因此您需要将其除以屏幕的宽度,以便在使用的任何显示器上进行相同的移动。 You may also want to include a sensitivity multiplier so that the user may choose how fast panning is. 您可能还希望包括一个灵敏度倍增器,以便用户可以选择平移的速度。

It's often helpful to allow rotation of the camera using the same input by checking whether a key is held down. 通过检查按键是否被按下来允许使用相同的输入旋转摄像机通常是有帮助的。 Consider this pseudocode: 考虑以下伪代码:

void updateCamera() {
    if (LeftShiftPressed()) {
        RotateCamera(getNormalizedX());
    } else {
        PanCamera(getNormalizedX());
    }
}

float getNormalizedX() {
    return float(getDeltaX()) / float(getScreenWidth())
}

void PanCamera(float x_movement) {
    // pan by x_movement * pan_multiplier
}

void RotateCamera(float x_movement) {
    // rotate by x_movement * rotation_multiplier
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM