Created
October 27, 2013 13:05
-
-
Save davidB/7181741 to your computer and use it in GitHub Desktop.
[Using game_loop with dartemis](http://dwayneb.free.fr/posts/using_gameloop_with_dartemis/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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