Examples - Stop Running Automatically
This commit is contained in:
parent
bf16d96600
commit
0124a2ce2c
5 changed files with 7 additions and 18 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue