我的问题是,每当我尝试在鼠标悬停在图像上时更改图像时,它都不会改变,并且当我执行 playgame.destroy(); 它只是在它后面显示一个白屏,而不是其他图像。这是我的代码:
import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class Menu extends BasicGameState {
Image playgame;
Image exitgame;
Image playgame_hover;
Image exitgame_hover;
public String mouse = "No Input Yet!";
public Menu(int state) {
}
@Override
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
playgame = new Image("res/playgame.png");
exitgame = new Image("res/exitgame.png");
playgame_hover = new Image("res/playgame_hover.png");
exitgame_hover = new Image("res/exitgame_hover.png");
}
@Override
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
g.drawString(mouse, 590, 10);
playgame.draw(100,100);
exitgame.draw(100, 200);
}
@Override
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
Input input = gc.getInput();
int mousex = Mouse.getX();
int mousey = Mouse.getY();
mouse = "Mouse coordinate x: " + mousex + " y: " + mousey;
// x-min:105 x-max:300 y-min: y-max:300
if(input.isMouseButtonDown(0)) {
if((mousex>100 && mousex<600) && (mousey>357 && mousey<437)) {
sbg.enterState(1);
}
if((mousex>100 && mousex<600) && (mousey>257 && mousey <337)) {
System.exit(0);
}
}
if((mousex>100 && mousex<600) && (mousey>357 && mousey<437)) {
playgame.destroy();
playgame_hover.draw(100, 100);
}
if((mousex>100 && mousex<600) && (mousey>257 && mousey <337)) {
exitgame.destroy();
exitgame_hover.draw(100, 200);
}
}
@Override
public int getID() {
return 0;
}
}