我正在用java开始一个非常简单的游戏,但我已经卡在第一步了。我创建了一个 StateBasedGame 类 (Kreations),它成功添加并进入并初始化了我的 BasicGameState (MenuGameState)。但是没有调用 MenuGameState 的 update() 和 render() 方法 - 我很难弄清楚原因。你能帮我吗?下面是代码:
基于状态的游戏:
import gamestates.MenuGameState;
import org.newdawn.slick.*;
import org.newdawn.slick.state.StateBasedGame;
public class Kreations extends StateBasedGame
{
public Kreations() {
super("Kreations");
}
@Override
public void update(GameContainer gc, int delta) throws SlickException
{
}
@Override
public void render(GameContainer gc, Graphics g) throws SlickException
{
}
public static void main(String[] args) throws SlickException
{
try {
AppGameContainer container = new AppGameContainer(new Kreations());
container.setDisplayMode(800,600,false);
//Make sure the logic updates consistently
container.setMinimumLogicUpdateInterval(20);
container.setMaximumLogicUpdateInterval(20);
container.start();
} catch (SlickException e) {
e.printStackTrace();
}
}
@Override
public void initStatesList(GameContainer gc) throws SlickException {
this.addState(new MenuGameState());
}
}
基本游戏状态:
package gamestates;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
public class MenuGameState extends BasicGameState {
public static final int ID = GameStates.MAIN_MENU.ordinal();
@Override
public void init(GameContainer gc, StateBasedGame sbg)
throws SlickException {
}
@Override
public void render(GameContainer gc, StateBasedGame sbg, Graphics g)
throws SlickException {
g.drawString("Hello World", 100, 100);
}
@Override
public void update(GameContainer gc, StateBasedGame sbg, int delta)
throws SlickException {
}
@Override
final public int getID() {
// TODO Auto-generated method stub
return GameStates.MAIN_MENU.ordinal();
}
public void enter(GameContainer container, StateBasedGame game) throws SlickException {
System.out.print("MenuGameState.enter() is called");
}
}