滑动2d光标消失错误



开始游戏后不久,每当我试图将光标带回游戏窗口时,光标就会消失并开始弹出,然后再次消失在窗口中。这是使用自定义光标的类的代码:


import org.lwjgl.input.Mouse;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
public class Clicker extends BasicGameState {
Flower flower = new Flower();

public Clicker(int state) {
}
public void init(GameContainer container, StateBasedGame game) throws SlickException {
container.setMouseCursor("res/cursor/cursor.png", 0, 0);

flower.flower = new Image("res/flower.png");
}
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
g.drawImage(flower.flower, flower.X, flower.Y);
}
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
if (Mouse.isButtonDown(0)) {
container.setMouseCursor("res/cursor/cursor_pressed.png", 0, 0);
if (flower.hitbox.contains(Mouse.getX(), 750 - Mouse.getY())) {
flower.newX();
flower.newY();      
}

} else {
container.setMouseCursor("res/cursor/cursor.png", 0, 0);
}
}
public int getID() {
return 2;
}
}

所以我不久前解决了这个问题,但最好的办法是用空白图像替换光标,然后为实际光标制作一个新的精灵,并将其位置设置为鼠标的位置。

最新更新