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. I'd like to avoid using libgdx's scene2d if possible. However, I can't see to find a way to capture horizontal scrolls. Is there anyway to detect a horizontal mouse scroll in Libgdx? I'd like to avoid using libgdx's scene2d if possible. And if there is not, is there a way to do it using plain java, without using awt, swing, or javafx?
1 Answers
0
votes
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()
. 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
}