Slick2D没有检测到鼠标移动

时间:2014-12-31 19:49:49

标签: java lwjgl slick2d

最近安装了Slick2D,但似乎它没有检测到任何鼠标光标位置的变化,即使用mousePressed方法总是返回相同的位置。这可能是由于lwjgl原生代的变化吗?我觉得没有人再使用Slick2D ......

代码:

package grajus;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

public class GameStart extends StateBasedGame {

public GameStart(String title) {
    super(title);
}

public static void main(String[] args) {

    try {
        AppGameContainer game = new AppGameContainer(new GameStart("Game"));    
        game.setDisplayMode(640, 480, false);
        game.start();
    } catch (SlickException e) {
        e.printStackTrace();
    }
}

@Override
public void initStatesList(GameContainer arg0) throws SlickException {
    addState (new GameState());
}

class GameState extends BasicGameState {

    @Override
    public void init(GameContainer arg0, StateBasedGame arg1)
            throws SlickException {}

    @Override
    public void render(GameContainer arg0, StateBasedGame arg1,
            Graphics arg2) throws SlickException {}

    @Override
    public void update(GameContainer arg0, StateBasedGame arg1, int arg2)
            throws SlickException {}

    @Override
    public int getID() {
        return 0;
    }

    @Override
    public void mousePressed(int button, int x, int y) {
        System.out.println(x + " " + y);            // no matter where I press I get -161 481
    }

}

}

1 个答案:

答案 0 :(得分:0)

对于今天遇到此问题的其他人,我可以通过更新到最新的lwjgl版本2.9.3修复它

更新lwjgl版本后,正确检测到鼠标位置。