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; Game game;
bool running = false; bool running = false;
SimpleLoop(Game this.game) { SimpleLoop(Game this.game);
eventloop();
}
void eventloop() { void eventloop() {
while (true) { while (running) {
update(); update();
} }
} }
@ -37,6 +35,7 @@ class SimpleLoop implements LoopExample {
} }
void start() { void start() {
eventloop();
running = true; running = true;
} }
} }

View file

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

View file

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

View file

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

View file

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