Examples - Stop Running Automatically

This commit is contained in:
Marty Oehme 2018-07-20 19:02:54 +02:00
parent bf16d96600
commit 0124a2ce2c
5 changed files with 7 additions and 18 deletions

View file

@ -16,12 +16,10 @@ class SimpleLoop implements LoopExample {
Game game;
bool running = false;
SimpleLoop(Game this.game) {
eventloop();
}
SimpleLoop(Game this.game);
void eventloop() {
while (true) {
while (running) {
update();
}
}
@ -37,6 +35,7 @@ class SimpleLoop implements LoopExample {
}
void start() {
eventloop();
running = true;
}
}

View file

@ -11,9 +11,7 @@ class WhileLoop implements LoopExample {
Game game;
num id;
WhileLoop(Game this.game) {
window.requestAnimationFrame(eventloop);
}
WhileLoop(Game this.game);
void eventloop(num time) {
game.update();

View file

@ -12,9 +12,7 @@ class VariableTimestep implements LoopExample {
num id;
Stopwatch elapsed = new Stopwatch();
VariableTimestep(Game this.game) {
window.requestAnimationFrame(eventloop);
}
VariableTimestep(Game this.game);
void eventloop(num time) {
int dt = elapsed.elapsedMilliseconds;

View file

@ -11,10 +11,7 @@ class FixedLoopVariableRender implements LoopExample {
Game game;
num id;
FixedLoopVariableRender(this.game) {
elapsed.start();
window.requestAnimationFrame(eventloop);
}
FixedLoopVariableRender(this.game);
void eventloop(num time) {
lag += elapsed.elapsedMilliseconds;

View file

@ -12,10 +12,7 @@ class DirtyFlagRender implements LoopExample {
num id;
bool dirty = true;
DirtyFlagRender(this.game) {
elapsed.start();
window.requestAnimationFrame(eventloop);
}
DirtyFlagRender(this.game);
void eventloop(num time) {
lag += elapsed.elapsedMilliseconds;