Application structure and controls¶
A small prototype can live entirely in SimpleApplication, but as a game grows it helps to separate its responsibilities. An AppState can manage a menu, a level or an input mode, while a Control attaches behavior to a particular spatial. Attach a state with stateManager.attach(...); its lifecycle provides places for initialization, updates and cleanup. When the state is detached, remove its listeners and release the resources it owns.
A control is added with spatial.addControl(...). For example, a custom AbstractControl implements controlUpdate(float tpf) for behavior and controlRender(...) when render-time work is required. Avoid keeping unrelated game systems in the scene graph merely because they need updates.
Keep scene-graph changes and most renderer operations on the render thread. Background threads are useful for work such as file or network I/O; when that work finishes, use enqueue to apply its result to the running application. Avoid blocking the render thread while long operations complete.
See the AppState API and Control API.