From 0124a2ce2c5ebbcabaa5ed1132088144bf97f3dc Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 20 Jul 2018 19:02:54 +0200 Subject: [PATCH] Examples - Stop Running Automatically --- lib/src/01-WhileLoop.dart | 7 +++---- lib/src/02-AnimationFrameWhile.dart | 4 +--- lib/src/03-VariableTimestep.dart | 4 +--- lib/src/04-FixedLoopVariableRender.dart | 5 +---- lib/src/05_DirtyFlagRendering.dart | 5 +---- 5 files changed, 7 insertions(+), 18 deletions(-) diff --git a/lib/src/01-WhileLoop.dart b/lib/src/01-WhileLoop.dart index 4c00373..7ed028a 100644 --- a/lib/src/01-WhileLoop.dart +++ b/lib/src/01-WhileLoop.dart @@ -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; } } diff --git a/lib/src/02-AnimationFrameWhile.dart b/lib/src/02-AnimationFrameWhile.dart index 1f2b11c..5421325 100644 --- a/lib/src/02-AnimationFrameWhile.dart +++ b/lib/src/02-AnimationFrameWhile.dart @@ -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(); diff --git a/lib/src/03-VariableTimestep.dart b/lib/src/03-VariableTimestep.dart index 668a508..dd0ef62 100644 --- a/lib/src/03-VariableTimestep.dart +++ b/lib/src/03-VariableTimestep.dart @@ -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; diff --git a/lib/src/04-FixedLoopVariableRender.dart b/lib/src/04-FixedLoopVariableRender.dart index 6c00672..5c8d6a4 100644 --- a/lib/src/04-FixedLoopVariableRender.dart +++ b/lib/src/04-FixedLoopVariableRender.dart @@ -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; diff --git a/lib/src/05_DirtyFlagRendering.dart b/lib/src/05_DirtyFlagRendering.dart index 1a71038..b233c80 100644 --- a/lib/src/05_DirtyFlagRendering.dart +++ b/lib/src/05_DirtyFlagRendering.dart @@ -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;