我在Intellij的Windows 10环境中使用Slick2D创建了一个简单的鼠标监听器示例。它没有报告正确的坐标或根本没有工作:
州级:
import org.lwjgl.input.Mouse;
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 StateMain extends BasicGameState
{
@Override
public int getID() {return 0;}
@Override
public void init(GameContainer container, StateBasedGame game) throws SlickException {}
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {}
@Override
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException
{
System.out.printf("Position: %d,%d\n", Mouse.getX(), Mouse.getY()); // Only reports position (-1,-1)
}
@Override
public void mouseClicked(int button, int x, int y, int clickCount)
{
System.out.printf("Clicked: %d,%d\n", x, y); // Doesn't report
}
@Override
public void mousePressed(int button, int x, int y)
{
System.out.printf("Pressed: %d,%d\n", x, y); // Only reports (-1,501)
}
}
我的libs文件夹中有以下文件:
jinput-dx8.dll jinput-dx8_64.dll jinput-raw.dll jinput-raw_64.dll lwjgl.dll lwjgl64.dll OpenAL32.dll OpenAL64.dll
以下是我的VM参数:
-Djava.library.path = libs / -Dorg.lwjgl.opengl.Display.allowSoftwareOpenGL = true
运行代码时总是出现以下错误:
2017年10月5日上午11:26:30 net.java.games.input.DefaultControllerEnvironment getControllers 警告:找到未知的Windows版本:Windows 10 2017年10月5日上午11:26:30 net.java.games.input.DefaultControllerEnvironment getControllers 信息:尝试使用默认的Windows插件。 2017年10月5日上午11:26:30 net.java.games.input.DefaultControllerEnvironment getControllers 信息:正在加载:net.java.games.input.DirectAndRawInputEnvironmentPlugin
我怀疑它正在加载的输入环境插件导致奇怪的鼠标位置错误?
答案 0 :(得分:1)
这对我有用。你能尝试lwjgl 2.9.1并把它放在你的init方法中:System.setProperty(“org.lwjgl.input.Mouse.allowNegativeMouse Coords”,“false”);