-
Notifications
You must be signed in to change notification settings - Fork 0
Managing States
In most cases, your simulation will have multiple states, and you will need to transition between them (e.g., from a menu state to a gameplay state).
The StateManager is responsible for managing the various states of your simulation, allowing you to register, switch, update, render, and dispose of states.
The StateManager is globally accessible via the OIS class. To access the StateManager in your code, use the following reference:
StateManager stateManager = OIS.stateManager;This gives you access to the methods provided by StateManager to manipulate and control the simulation's states.
To stop the simulation gracefully, you can call the stop() method on the SimulationEngine. This method will terminate the application by invoking the exit() and dispose() methods of the underlying application instance.
OIS.engine.stop();This will ensure the simulation stops in a clean and controlled manner.
To transition between different states during the simulation, you can use the changeState() method of the StateManager. This method allows you to switch from one state to another by specifying the key that was registered in the simulation.ois file.
When you change states:
- The current state is exited using the
exit()method. - The new state is entered using the
enter()method. - The new state can optionally receive parameters upon entry.
Assume you have registered the state MyState with the key "Gameplay" in your simulation.ois file:
{
"states": {
"Gameplay": "com.mygame.GameplayState"
}
}Inside your current state, you can transition to Gameplay by calling:
@Override
public boolean update(float dt) {
if (someConditionMet) {
// Transition to Gameplay state
OIS.stateManager.changeState("Gameplay", optionalParams);
return false; // Indicates the current state is finished and should be exited
}
return true; // Continue running this state
}Go Back to Developer's Guide
© 2024