我希望在程序的任何时候通过提供文件名来更改光标。 我打电话给:
setCursor(defaultcursor);
函数setCursor
如下所示:
private void setCursor(String image)
{
File file = new File("res/Cursors/"+image+".png");
IntBuffer ib = null;
try {
FileChannel fc = new FileInputStream(file).getChannel();
ib = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size())
.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();
ib.rewind();
} catch (IOException e1) {
e1.printStackTrace();
}
try
{
org.lwjgl.input.Cursor cursor = new org.lwjgl.input.Cursor(32, 32, 0, 0, 1, ib, null);
Mouse.setNativeCursor(cursor);
}
catch (LWJGLException e)
{
e.printStackTrace();
}
}
问题是我在屏幕上看到的只是一些彩色像素。根本不是我想要的形象。 当我想增加宽度和高度时。我收到这个错误:
Exception in thread "main" java.lang.IllegalArgumentException: Number of remaining buffer elements is 184, must be at least 1024. Because at most 1024 elements can be returned, a buffer with at least 1024 elements is required, regardless of actual returned element count
at org.lwjgl.BufferChecks.throwBufferSizeException(BufferChecks.java:162)
at org.lwjgl.BufferChecks.checkBufferSize(BufferChecks.java:189)
at org.lwjgl.input.Cursor.<init>(Cursor.java:89)
at Entities.Player.setCursor(Player.java:86)
at Entities.Player.checkInputs(Player.java:138)
at Entities.Player.move(Player.java:51)
at EngineTester.MainGameLoop.main(MainGameLoop.java:82)