Examples - Make Example Class Canvas pass through to Game
This commit is contained in:
parent
0124a2ce2c
commit
b7a6f67d24
1 changed files with 15 additions and 7 deletions
|
@ -6,21 +6,30 @@ import 'package:browserloop/src/04-FixedLoopVariableRender.dart';
|
|||
import 'package:browserloop/src/02-AnimationFrameWhile.dart';
|
||||
import 'package:browserloop/src/05_DirtyFlagRendering.dart';
|
||||
|
||||
CanvasElement baseCanvas = new CanvasElement(width: 480, height: 480);
|
||||
|
||||
List<Example> examples = [
|
||||
Example("While Loop Example", "#while_loop"),
|
||||
Example("Fixed Update, Variable Render", "#fixed_variable"),
|
||||
Example("Variable Timestep", "#variable_timestep"),
|
||||
Example("Variable Render with Dirty Flag", "#dirty_flag")
|
||||
Example("While Loop Example", "#while_loop", new WhileLoop(new Game(baseCanvas))),
|
||||
Example("Variable Timestep", "#variable_timestep", new VariableTimestep(new Game(baseCanvas))),
|
||||
Example("Fixed Update, Variable Render", "#fixed_variable", new FixedLoopVariableRender(new Game(baseCanvas))),
|
||||
Example("Variable Render with Dirty Flag", "#dirty_flag", new DirtyFlagRender(new Game(baseCanvas)))
|
||||
];
|
||||
LoopExample active;
|
||||
|
||||
class Example {
|
||||
final String query;
|
||||
final String name;
|
||||
CanvasElement canvas = CanvasElement(width: 480, height: 480);
|
||||
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() {
|
||||
|
@ -97,7 +106,6 @@ void activate(MouseEvent e) {
|
|||
ex.loop = new DirtyFlagRender(new Game(ex.canvas));
|
||||
break;
|
||||
}
|
||||
if (ex.canvas != ex.loop.game.canvas) ex.loop.game.canvas = ex.canvas;
|
||||
addControls(ex);
|
||||
} else {
|
||||
resetExample(ex);
|
||||
|
|
Loading…
Reference in a new issue