Examples - Make Example Class Canvas pass through to Game

This commit is contained in:
Marty Oehme 2018-07-20 19:03:46 +02:00
parent 0124a2ce2c
commit b7a6f67d24

View file

@ -6,21 +6,30 @@ import 'package:browserloop/src/04-FixedLoopVariableRender.dart';
import 'package:browserloop/src/02-AnimationFrameWhile.dart'; import 'package:browserloop/src/02-AnimationFrameWhile.dart';
import 'package:browserloop/src/05_DirtyFlagRendering.dart'; import 'package:browserloop/src/05_DirtyFlagRendering.dart';
CanvasElement baseCanvas = new CanvasElement(width: 480, height: 480);
List<Example> examples = [ List<Example> examples = [
Example("While Loop Example", "#while_loop"), Example("While Loop Example", "#while_loop", new WhileLoop(new Game(baseCanvas))),
Example("Fixed Update, Variable Render", "#fixed_variable"), Example("Variable Timestep", "#variable_timestep", new VariableTimestep(new Game(baseCanvas))),
Example("Variable Timestep", "#variable_timestep"), Example("Fixed Update, Variable Render", "#fixed_variable", new FixedLoopVariableRender(new Game(baseCanvas))),
Example("Variable Render with Dirty Flag", "#dirty_flag") Example("Variable Render with Dirty Flag", "#dirty_flag", new DirtyFlagRender(new Game(baseCanvas)))
]; ];
LoopExample active; LoopExample active;
class Example { class Example {
final String query; final String query;
final String name; final String name;
CanvasElement canvas = CanvasElement(width: 480, height: 480);
LoopExample loop; LoopExample loop;
Example(this.name, this.query); Example(this.name, this.query, this.loop);
CanvasElement get canvas {
if(loop != null) return loop.game.canvas;
return new CanvasElement(width: 480, height: 480);
}
set canvas(CanvasElement canvas) {
if(loop != null) loop.game.canvas = canvas;
}
} }
void main() { void main() {
@ -97,7 +106,6 @@ void activate(MouseEvent e) {
ex.loop = new DirtyFlagRender(new Game(ex.canvas)); ex.loop = new DirtyFlagRender(new Game(ex.canvas));
break; break;
} }
if (ex.canvas != ex.loop.game.canvas) ex.loop.game.canvas = ex.canvas;
addControls(ex); addControls(ex);
} else { } else {
resetExample(ex); resetExample(ex);