If you change the cursor via setMouseCursor "a whole bunch", then it blows up.
the reason I'm doing it 'a whole bunch' is because I'm updating the cursor based on the state of the game (ie. different cursor when over enemy, versus when over the hud or a friendly target, etc).
Here is some example code, it's excessive; but just put it in there so you could see what it does. the 3 images are just png images 31x31 pixels. Let it run 30-60 seconds and you will see it.
Code:
import org.newdawn.slick.Animation;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Color;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.util.Log;
public class MouseTest extends BasicGame {
private String cursorSelect;
private String cursorNone;
private String cursorNo;
public MouseTest() { super("MouseTest"); }
public static void main(String [] arguments) {
try {
AppGameContainer app = new AppGameContainer(new MouseTest());
app.setDisplayMode(600,480,false);
app.setShowFPS(true);
app.setVerbose(true);
app.setTitle("Mouse Test");
app.start();
} catch (SlickException e) {
e.printStackTrace();
}
}
@Override
public void init(GameContainer container) throws SlickException {
cursorSelect = "gfx/cursors/cursorSelect.png";
cursorNone= "gfx/cursors/cursorNone.png";
cursorNo= "gfx/cursors/cursorNo.png";
}
@Override
public void update(GameContainer container, int delta) throws SlickException {
container.setMouseCursor(cursorNone, 15, 15);
container.setMouseCursor(cursorNo, 15, 15);
container.setMouseCursor(cursorSelect, 15, 15);
}
public void render(GameContainer container, Graphics g) throws SlickException {
container.setMouseCursor(cursorNone, 15, 15);
container.setMouseCursor(cursorNo, 15, 15);
container.setMouseCursor(cursorSelect, 15, 15);
}
}
Here is the error it spits out:
Code:
Thu Oct 16 19:52:33 CDT 2008 INFO:Chances are you cursor is too small for this platform
Thu Oct 16 19:52:33 CDT 2008 ERROR:Failed to load and apply cursor.
Thu Oct 16 19:52:33 CDT 2008 ERROR:org.lwjgl.LWJGLException: Could not allocate DIB section.
org.lwjgl.LWJGLException: org.lwjgl.LWJGLException: Could not allocate DIB section.
at org.newdawn.slick.opengl.CursorLoader.getCursor(CursorLoader.java:81)
at org.newdawn.slick.AppGameContainer.setMouseCursor(AppGameContainer.java:208)
at Cursor.setCursor(Cursor.java:181)
at MountainDefender.renderValidArea(MountainDefender.java:341)
at MountainDefender.render(MountainDefender.java:237)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:576)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:371)
at MountainDefender.main(MountainDefender.java:134)
Caused by: org.lwjgl.LWJGLException: Could not allocate DIB section.
at org.lwjgl.opengl.WindowsDisplay.nCreateCursor(Native Method)
at org.lwjgl.opengl.WindowsDisplay.doCreateCursor(WindowsDisplay.java:519)
at org.lwjgl.opengl.WindowsDisplay.createCursor(WindowsDisplay.java:515)
at org.lwjgl.input.Cursor.createCursors(Cursor.java:192)
at org.lwjgl.input.Cursor.<init>(Cursor.java:107)
at org.newdawn.slick.opengl.CursorLoader.getCursor(CursorLoader.java:78)
... 7 more