Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Game {
var _world;
var _renderSystem;
var _gameLoop;
Game(){
// create instance
var container = query("#game");
_world = new World();
_gameLoop = new GameLoopHtml(container);
_renderSystem = new System_RenderX(container);
// setup instance an allow circular dependencies gameLoop <-> world'system
_setupWorld();
_setupGameLoop();
}
void _setupWorld() {
//...
_world.addSystem(new System_XXXX());
_world.addSystem(new System_YYYY(_gameLoop));
// System(s) in charge of rendering will not run when world.process()
_world.addSystem(_renderSystem, passive: true);
_world.initialize();
}
void _setupGameLoop(){
_gameLoop.pointerLock.lockOnClick = false; // to keep mouse cursor
_gameLoop.onUpdate = (gameLoop){
_world.delta = gameLoop.dt * 1000.0; // world.delta in ms
_world.process();
};
_gameLoop.onRender = (gameLoop){
_renderSystem.process();
};
}
void start() => _gameLoop.start();
void stop() => _gameLoop.stop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.