MxR
MxR

Reputation: 150

LWJGL Mouse scroll wheel getDWheel() Method

I use the getDWheel method in my game like so:

public void checkMouseWheel() {
if (highLight != null) {
    if (Mouse.getDWheel() < 0) {
        System.out.println("DOWN");
    }
    if (Mouse.getDWheel() > 0){
        System.out.println("UP");
   }
}

I call this method every time I check for input. When I use the scroll wheel the program only reaches the DOWN part when I scroll up, It doesn't get into the if... No matter what I do only the scroll down works.

EDIT: When I scroll down ingame it prints "DOWN" but when I scroll up ingame nothing is printed.

Upvotes: 1

Views: 5182

Answers (1)

bfishman
bfishman

Reputation: 579

According to the javadoc, Mouse.getDWheel() "returns Movement of the wheel since last time getDWheel() was called"

So when you call it the first time, the information is 'cleared out', and therefore will always return 0 for the second call. Try this small change to fix it:

public void checkMouseWheel() {
if (highLight != null) {
    int dWheel = Mouse.getDWheel();
    if (dWheel < 0) {
        System.out.println("DOWN");
    } else if (dWheel > 0){
        System.out.println("UP");
   }
}

Upvotes: 5

Related Questions