Standard Game Update

I went through the tutorials on starting to use Standard Game. My problem is that I don't know how to make an update method. Is there a way to override it, or is the game loop my responsibility?

With standardgame you have to create GameStates, where logic and render methods are in.

After creating a GameState, you can add it to GameStateManager.getInstance(), it will be updated and rendered.



Greetz

Snare

If you create your own GameState by extending BasicGameState, that superclass already has an update method that will update the geometric state: you don't have to explicitly implement everything yourself.  However, if there is anything else you want to do specifically in your sub-class every time through the loop, you can override the update method (just follow the signature). 

I did what mjsimpson said, and I got a NullPointerException. I extended BasicGameState, and changed the update method to update my input too. Here is my source for the extension:

import com.jmex.game.state.BasicGameState;
public class BasicGameState2 extends BasicGameState {
    boolean printed = false;
    BasicGameState2(String name) {
        super(name);
    }
    @Override
    public void update(float tpf) {
        super.update(tpf);
        try {
            Main.input.update(tpf);
        } catch(Exception e) {
            if (printed==false) {
                e.printStackTrace();
                printed = true;
            }
        }
    }
}


And here is the NPC:

java.lang.NullPointerException
        at demoapp.BasicGameState2.update(BasicGameState2.java:14)
        at com.jmex.game.state.GameStateNode.update(GameStateNode.java:71)
        at com.jmex.game.StandardGame.update(StandardGame.java:353)
        at com.jmex.game.StandardGame.run(StandardGame.java:225)
        at java.lang.Thread.run(Thread.java:619)


Apparently it happened while it was updating. Did I type the method wrong? All I did in the Main file was declare input like this:

public static InputHandler input;


Please, any help would be appreciated, I want to get my game going somewhere.

Assuming the null pointer exception was on the line calling Main.input.update(tpf), the issue is that the "input" member has yet to be initialized.  You have created the variable, but not given it a value at this point ( input = new InputHandler(…) ).



You could add some check to see if it is null before you use it, or only enable that GameState after you've done all of your initialization that it relies on.

Oh. Lol. I'm an idiot. I never created it in the first place. :smiley: