私はJavaゲームのビデオチュートリアルに従っています(そこから離れることができます)が、ボタンの1つ(終了ボタン)が機能しません。助けてください。lwjgl と slick を使用しています。
メインクラス:
package javagame;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class Game extends StateBasedGame {
public static final String gamename = "Java Game Alpha 1.0";
public static final int menu = 0;
public static final int play = 1;
public Game(String gamename) {
super(gamename);
this.addState(new Menu(menu));
this.addState(new Play(play));
}
public void initStatesList(GameContainer gc) throws SlickException{
this.getState(menu).init(gc, this);
this.getState(play).init(gc, this);
this.enterState(menu);
}
public static void main(String[] args) {
AppGameContainer appgc;
try{
appgc = new AppGameContainer(new Game(gamename));
appgc.setDisplayMode(1600, 800, false);
appgc.start();
}catch(SlickException e) {
e.printStackTrace();
}
}
}
メニュークラス:
package javagame;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
import org.lwjgl.input.Mouse;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.GameState;
import org.newdawn.slick.state.StateBasedGame;
public class Menu implements GameState {
Image PlayNow;
Image exitGame;
public Menu(int state){
}
@Override
public void mouseClicked(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void mouseDragged(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void mouseMoved(int arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(int arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(int arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void mouseWheelMoved(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void inputEnded() {
// TODO Auto-generated method stub
}
@Override
public void inputStarted() {
// TODO Auto-generated method stub
}
@Override
public boolean isAcceptingInput() {
// TODO Auto-generated method stub
return false;
}
@Override
public void setInput(Input arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(int arg0, char arg1) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(int arg0, char arg1) {
// TODO Auto-generated method stub
}
@Override
public void controllerButtonPressed(int arg0, int arg1) {
// TODO Auto-generated method stub
}
@Override
public void controllerButtonReleased(int arg0, int arg1) {
// TODO Auto-generated method stub
}
@Override
public void controllerDownPressed(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void controllerDownReleased(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void controllerLeftPressed(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void controllerLeftReleased(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void controllerRightPressed(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void controllerRightReleased(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void controllerUpPressed(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void controllerUpReleased(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void enter(GameContainer arg0, StateBasedGame arg1)
throws SlickException {
// TODO Auto-generated method stub
}
@Override
public int getID() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void init(GameContainer gc, StateBasedGame sbg)
throws SlickException {
// TODO Auto-generated method stub
PlayNow = new Image ("res/PlayNow.png");
exitGame = new Image ("res/exitGame.png");
}
@Override
public void leave(GameContainer arg0, StateBasedGame arg1)
throws SlickException {
// TODO Auto-generated method stub
}
@Override
public void render(GameContainer gc, StateBasedGame sbg, Graphics g)
throws SlickException {
// TODO Auto-generated method stub
g.drawString("It's time for an adventure!", 50, 50);
//g.drawRect(730, 320, 70, 80); //x, y, width, height
PlayNow.draw(680, 320, 250, 50);
exitGame.draw(680, 380, 250, 50);
int xpos = Mouse.getX();
int ypos = Mouse.getY();
g.drawString("Mouse Position: " + xpos + " " + ypos, 10, 22);
}
@Override
public void update(GameContainer gc, StateBasedGame sbg, int delta)
throws SlickException {
// TODO Auto-generated method stub
int xpos = Mouse.getX();
int ypos = Mouse.getY();
Input input = gc.getInput();
//play now
if( (xpos > 683) && (xpos < 920) && (ypos > 440) && (ypos < 478) ) {
if(Mouse.isButtonDown(0)) {
sbg.enterState(1);
}
//exit Game
if ( (xpos > 683) && (xpos < 920) && (ypos > 379) && (ypos < 417) ) {
if(Mouse.isButtonDown(0)) {
gc.exit();
}
}
}
}
}
もう1つのクラスがありますが、それは問題ではありません。助けてください!