Dan, I’ve got a sneaking suspicion that you might need to go and review program structure a little bit, particularly in terms of Java & OOP (as evidenced by the code snippet you have provided, and by the way that you just lumped the update() method there). Just to give you some real quick pointers:
- A game is generally a repeated loop, in which you 1) update logic, then 2) render it. I.e.:
public void go() {
while(running) {
//Do some timing calculations to determine delta.
update(delta);
render();
try {
Thread.sleep(sleepTime); //sleepTime being calculated from your timing too.
} catch(InterruptedException ex) {
}
}
}
-
In the case of a state based game, States could be considered objects that have their own update() and render() methods. I.e. they handle all their updating and rendering themselves. Then your main game loop just becomes a case of calling the update() and render() methods on the current state, passing them the required parameters.
-
Instead of controlling program flow by having switches in your render or update methods, hold a reference to the current state somewhere (i.e. State currentState). Then instead of switches, you simply call currentState.update(delta);, currentState.render();.
-
In your particular case, the introState could hold its own timer variables, and handle the timing within it’s own update(delta) method (hence this is where the timer stuff I provided would be ideally located). Once the timing criteria are met, the introState then passes on control to the next state. (In a simple case it could do this itself by setting currentState to the next desired state. In a more complex case, it might interact with a form of state manager which handles current, reserved and transitioning states).
Right, that’s it. Very, very sorry if I have taught you to suck eggs with any of this, or made any silly assumptions.
Cheers.
EDIT: I should add that this is “program structure according to nerb” which may not be the right, best, or only way of doing things. You’ve obviously got some grasp on the concepts, but it just looks very messy to me. You have a mixture of state-handled rendering, non-state handled rendering, and no evidence of a solid update() method either in or outside of your states. Structure like this might suffice for a very small program, but I foresee you running in to trouble soon as things grow in size &/or complexity.