Lifecycle Overview
In awe, Scripts, Components and Behaviors have special lifecycle methods that run at key moments:
main
export default class GameManager {
elapsedTime = 0;
maxGameTime = 10;
onStart() {
this.elapsedTime = 0;
}
// this is what you often hear as the game loop
// it will run at every frame, eg. 60fps means this runs 60 times / second
onUpdate(dt: number) {
this.elapsedTime += dt;
}
}
onPreload()
Runs before asset loading; ideal for async setup or resource definitions.
onReady()
Called after all assets load. Put one-time initializations here.
onStart()
Triggers each time the game starts. Good for resetting positions, timers, etc.
onUpdate(dt)
Runs every frame. dt
is elapsed time since last frame. Handle movement, collision, and real-time logic here.
onPause()
/ onResume()
- Pause: Stop animations/timers.
- Resume: Reactivate paused elements.
onEnd()
Runs when the game ends (e.g., after World.stop()
).
onDispose()
The final cleanup hook after a session ends. Release or unsubscribe resources here.
Use these methods to manage your game’s flow and keep logic organized and responsive.