Changes
- Added functionality within the StateManager class to track how many frames per second (FPS) our game is running at.
To-Do
- Implement dynamic on-screen text to track FPS without having to check the console
- Implement a way to show/hide diagnostic data while in-game
Known Bugs
- There is no way to unselect a tower other than paying for it and placing it on a valid tile
Changes — Extended
FPS Counter:
The following static variables were declared and initialized at the top of our StateManager class:
1 2 3 |
public static long nextSecond = System.currentTimeMillis() + 1000; public static int framesInLastSecond = 0; public static int framesInCurrentSecond = 0; |
We then used these variables within our update() method (which is called each update by the Boot class) to track how many frames pass each second and print the result to the console.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
public static void update() { switch(gameState) { case MAINMENU: if (mainMenu == null) mainMenu = new MainMenu(); mainMenu.update(); break; case GAME: if (game == null) game = new Game(map); game.update(); break; case EDITOR: if (editor == null) editor = new Editor(); editor.update(); break; } long currentTime = System.currentTimeMillis(); if (currentTime > nextSecond) { nextSecond += 1000; framesInLastSecond = framesInCurrentSecond; framesInCurrentSecond = 0; } framesInCurrentSecond++; System.out.println(framesInLastSecond + " fps"); } |