Gameloop and StandardGame

Hi,



I am using StandardGame. I was wondering how can I access game loop? That is, a function which is periodically called where I can update game. From API I can see that StandardGame has update() function. From description it seems to be the function that I need, but it seems I can't inherit StandardGame (it is final) and replace update() with my own function.



Thanks

You shouldn't use StandardGame this way…

Either, you create a GameState, and register it via GameStateManager,

      or, you extend from BaseGame.



If you want some debug information be displayed, you can extend SimpleGame, too.

sampie wrote:
I was wondering how can I access game loop?
tim8dev wrote:
You shouldn't use StandardGame this way..
+1
tim8dev wrote:
you create a GameState, and register it via GameStateManager

If you check out the Javadoc for GameState you'll find that also has update(), from which you can do your game related updating in  :D

Hi,



I got it working.



Thanks!

And are you willing to share what you have done to solve it?

ttrocha said:

And are you willing to share what you have done to solve it?


Looks like he solved it by extending GameState rather than the un-extendable StandardGame ;)  Point taken though, we love code samples and seeing fixes!

Hi,



Here is the code of how I accessed the game loop:



public class GameStateCP3D extends BasicGameState {

   
   public GameStateCP3D(String arg0) {
      super(arg0);
      // TODO Auto-generated constructor stub
   }

   public void update(float tpf) {
      super.update(tpf);
      Game.instance.gameLoop(tpf);
      
   }
}




                theGame = new StandardGame("CP3D");
      theGame.start();
      
      theGameState = new GameStateCP3D("cp3d");




public class Game {
   
   public static Game instance = null;
   
   public Game() {
      Game.instance = this;
   }
   
   public void gameLoop(float tpf) {
      // tpf = time elapsed since last frame
      
   }
   
}