mam jednoduchu java hru a chcem aby som mohol zapinat/vypinat FPS v okne.
Game.java
Kód: Vybrať všetko
package game;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class Game extends StateBasedGame {
public static final String gamename = "Game 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(640, 360, false);
appgc.setShowFPS(false);
appgc.start();
} catch (SlickException e) {
e.printStackTrace();
}
}
}
Play.java
Kód: Vybrať všetko
package game;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class Play extends BasicGameState {
public Play(int state) {
}
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
g.drawString("Playing ...", 10, 10);
}
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
Input input = gc.getInput();
if (input.isKeyPressed(Input.KEY_F)) {
//TO DO
//zmenit hodnotu setShowFPS(); na TRUE
}
}
public int getID() {
return 1;
}
}