LWJGL Mouse.getDX始终返回0

时间:2014-12-09 05:23:23

标签: java lwjgl mousemove

这是使用LWJGL版本2.9.1,我使用razer deatheradder鼠标在Windows 8.1上。

每当我拨打Mouse.getDX()Mouse.getDY()时,无论我移动鼠标的速度有多快或多远,它都会返回0。

Mouse.getX()有效且Mouse.getY()有效但getDXgetDY没有。

我一直在尝试重新创建getDXgetDY一段时间但是想提出这个问题,看看它是否能在我完成之前得到解答。

2 个答案:

答案 0 :(得分:2)

也许你每帧都在调用Mouse.setGrabbed(true);?我有这个问题,在将它移出渲染循环后,getDX工作了。

答案 1 :(得分:0)

我从来没有找到为什么Mouse.getDX和Mouse.getDY总是返回0的原因,但我认为我应该分享我的版本,以防其他人有同样的问题,所以他们不必创建自己的:

/*----NOTES----
 *This requires two variables saved
 *somewhere named mouseX and mouseY 

 *I only give getDX() as they are identical, just swap
 *dX -> dY   
 *currentX -> currentY  
 *Mouse.getX() -> Mouse.getY()  
 *mouseX -> mouseY:*/

public int getDX(){
    int dX = 0;
    int currentX = Mouse.getX();

    /*This is is only used because I am 
     *running my update mouse when Mouse.
     *isGrabbed is true, this prevents it 
     *from jumping right after you click */
    if(mouseX == 0){
        mouseX = currentX;
    }

    dX = Math.abs(mouseX - currentX);

    //Handles left/right movement
    if(mouseX > currentX){
        dX = -dX;
    }

    /*If the mouse was to go too far in
     *either direction it resets it */
    if(currentX >= Main.WIDTH - 25){
        currentX = 0;
    }
    else if(currentX == 0){
        currentX = Main.WIDTH - 25;
    }else{
        mouseX = currentX;
    }

    return dX;
}