【问题标题】:Having problems running game in Java Slick library and lwjgl在 Java Slick 库和 lwjgl 中运行游戏时遇到问题
【发布时间】:2016-05-28 06:55:58
【问题描述】:

我正在创建一个游戏,我正在使用 Slick 和 lwjgl。我的java版本是jdk1.7.0_79。这是我的代码:

package javagame;
 import org.newdawn.slick.AppGameContainer;
 import org.newdawn.slick.GameContainer;
 import org.newdawn.slick.SlickException;
 import org.newdawn.slick.state.GameState;
 import org.newdawn.slick.state.StateBasedGame;
/*
 * First we import the things we need
*/
public class Game extends StateBasedGame{
public static final String gamename="Ham Blaster";
public static final int menu =0;
public static final int play =1;
/*
* Startup things of our game
*/
public Game(String gamename) {
    super(gamename);
    this.addState((GameState) new Menu(menu));
    this.addState((GameState) new Play(play));

}
/*
 * Here we create the two states or screens of our game.
 */
public void initStatesList (GameContainer gc)throws SlickException{
    this.getState(menu).init(gc, this);
    this.getState(play).init(gc, this);
    this.enterState(menu);
}
/*
 * Here we set the display settings and this is going to be our main method.
 */
public static void main(String[]args){
    AppGameContainer appgc;
    try{
        appgc=new AppGameContainer(newGame(gamename));
        appgc.setDisplayMode(640, 360, false);
        appgc.start();
    }catch(SlickException e){
        e.printStackTrace();
    }
}
}

它给了我关于 newGame(gamename)) 的错误,说这个方法对于 Game 类型是未定义的。由于我使用的是 Eclipse,它会在出现错误时给我一些指示,并指示我为它创建一个方法。 Eclipse 创建了方法和方法代码:

    private static org.newdawn.slick.Game newGame(String gamename2) {
    // TODO Auto-generated method stub
    return null;
}

我应该在里面写什么? 这里还有另外两个屏幕的代码: 播放画面:

package javagame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.state.StateBasedGame;

 public class Play extends Exception {
  public Play(int play){
  }
  public void init (GameContainer gc, StateBasedGame sbg) throws Play {
  }
  /* 
   Render is used to draw things
   */
  public void render (GameContainer gc, StateBasedGame sbg, Graphics g)throws Play {
  }
  /*
   Update is used to update the images in your game
   */
  public void update (GameContainer gc, StateBasedGame sbg, Graphics g, int delta)throws Play{  
  }
  public int getID(){
      return 1;
}
}

还有菜单画面:

package javagame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.state.StateBasedGame;

 public class Menu extends Exception {
  public Menu(int menu) {}
      public void init (GameContainer gc, StateBasedGame sbg) throws Menu {
      }
      public void render (GameContainer gc, StateBasedGame sbg, Graphics g)throws Menu {
      }
      public void update (GameContainer gc, StateBasedGame sbg, Graphics g, int delta)throws Menu{  
      }
      public int getID(){
          return 0;
}

}

错误截图:

http://i.stack.imgur.com/8BamS.png

【问题讨论】:

    标签: java eclipse lwjgl slick


    【解决方案1】:

    你的问题很简单。不要写appgc=new AppGameContainer(newGame(gamename));,你需要写appgc=new AppGameContainer(new Game(gamename));

    【讨论】:

    • 仍然控制台不打印任何内容
    • 那个窗口打开了吗?当您单击运行按钮时,eclipse 是否会给您一个错误?
    • 单击“运行”按钮旁边的箭头,然后从菜单中选择“运行方式”并单击“Java 应用程序”
    • 它没有运行Java应用程序的选项可能是这个问题
    • 尝试用main方法打开类,然后作为Java应用程序运行
    猜你喜欢
    • 1970-01-01
    • 2021-07-24
    • 2013-02-03
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多