Reputation: 3
Ok, so I'm doing something wrong and I can't figure out what. I'm following a tutorial about building a simple game with Slick. I know there is almost nothing in the code, but at this point the code should be able to compile.
package javagame;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class Game extends StateBasedGame{
public static final String gamename = "Game name!";
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(640, 360, false);
appgc.start();
}catch(SlickException e){
e.printStackTrace();
}
}
}
And here are the classes
package javagame;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class Play {
public Play(int state){
}
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
}
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
}
public int getID(){
return 1;
}
}
and
package javagame;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class Menu {
public Menu(int state){
}
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
}
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
}
public int getID(){
return 0;
}
}
The error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method addState(GameState) in the type StateBasedGame is not applicable for the arguments (Menu)
The method addState(GameState) in the type StateBasedGame is not applicable for the arguments (Play)
at javagame.Game.<init>(Game.java:12)
at javagame.Game.main(Game.java:25)
Upvotes: 0
Views: 152
Reputation: 4262
As Game extends StateBasedGame
and it does not override addState()
, when you say this.addState(new Menu(menu));
it is trying to call method defined in StateBasedGame
API referance
So your Menu
and Play
class should be sub class of GameState
Upvotes: 1