ポーズメニューの画像があります。終了ボタンがあります。終了ボタンを押すと、ダイアログが表示されます。これは私が欲しいものです。
だから、私は画像を持っていて、マウスをクリックする必要がある場所の x と y の位置を設定して、ダイアログが表示されるようにします。私は次のようなことをしたい:
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
Input input = gc.getInput();
int xpos = Mouse.getX();
int ypos = Mouse.getY();
if ((xpos > 200 && xpos < 250) && (ypos > 230 && ypos < 260)) {
if (input.isMousePressed(0)) {
g.drawImage("res/Exit Confirmation.png", 200, 400)
}
上記のコードがそのようになることはありません。しかし、それに似た方法はありますか?
コードは次のとおりです。
import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class Menu extends BasicGameState {
public Menu(int state) {
}
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
Image background = new Image("res/Background.png");
g.drawImage(background, 0, 0);
Image play = new Image("res/Play Button.png");
g.drawImage(play, 275, 50);
Image exit = new Image("res/Exit Button.png");
g.drawImage(exit, 210, 250);
}
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
Input input = gc.getInput();
int xpos = Mouse.getX();
int ypos = Mouse.getY();
if ((xpos > 300 && xpos < 510) && (ypos > 230 && ypos < 260)) {
if (input.isMousePressed(0)) {
sbg.enterState(2); //this will take me to the game.
}
if ((xpos > 200 && xpos < 250) && (ypos > 230 && ypos < 260)) {
//i want this to actually show up a confirmation dialog with my image.
}
}
}
public int getID() {
return 1;
}
}
助けてください。ありがとう。