Lifecycle
Oxid loads the entry module defined in oxid.entry and expects that module to export a main() function.
Boot sequence
At startup, the runtime:
- evaluates the entry module
- calls
main() - stores the returned object
- compiles lightweight wrappers around the supported hooks
The supported hooks today are:
onInit()onUpdate(dt)onDraw()
All of them are optional.
Hook order
The runtime executes hooks in this order:
onInit()once, before the game loop beginsonUpdate(dt)every frameonDraw()every frame, after update
dt is the frame delta time provided by the renderer.
Example
import {GameObject} from 'oxid/core';
class MyApp extends GameObject {
onInit() {
console.log('ready');
}
onUpdate(dt) {
this.time = (this.time ?? 0) + dt;
}
onDraw() {
// draw here
}
}
export function main() {
return new MyApp();
}