Examples - Wire up Update Slider
This commit is contained in:
parent
7a87ad3749
commit
914b2aa5dd
4 changed files with 12 additions and 6 deletions
|
@ -6,3 +6,7 @@ abstract class LoopExample{
|
||||||
void stop() {}
|
void stop() {}
|
||||||
void start() {}
|
void start() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract class VariableUpdates {
|
||||||
|
double MS_PER_UPDATE = 300.0;
|
||||||
|
}
|
|
@ -3,8 +3,8 @@ import 'dart:html';
|
||||||
import 'package:browserloop/game/Game.dart';
|
import 'package:browserloop/game/Game.dart';
|
||||||
import 'package:browserloop/game/LoopExample.dart';
|
import 'package:browserloop/game/LoopExample.dart';
|
||||||
|
|
||||||
class FixedLoopVariableRender implements LoopExample {
|
class FixedLoopVariableRender implements LoopExample, VariableUpdates {
|
||||||
static final double MS_PER_UPDATE = 1000.0;
|
double MS_PER_UPDATE = 1000.0;
|
||||||
static final double SAFE_GUARD = 500.0;
|
static final double SAFE_GUARD = 500.0;
|
||||||
Stopwatch elapsed = new Stopwatch();
|
Stopwatch elapsed = new Stopwatch();
|
||||||
double lag = 0.0;
|
double lag = 0.0;
|
||||||
|
|
|
@ -3,8 +3,8 @@ import 'dart:html';
|
||||||
import 'package:browserloop/game/Game.dart';
|
import 'package:browserloop/game/Game.dart';
|
||||||
import 'package:browserloop/game/LoopExample.dart';
|
import 'package:browserloop/game/LoopExample.dart';
|
||||||
|
|
||||||
class DirtyFlagRender implements LoopExample {
|
class DirtyFlagRender implements LoopExample, VariableUpdates {
|
||||||
static final double MS_PER_UPDATE = 1000.0;
|
double MS_PER_UPDATE = 1000.0;
|
||||||
static final double SAFE_GUARD = 500.0;
|
static final double SAFE_GUARD = 500.0;
|
||||||
Stopwatch elapsed = new Stopwatch();
|
Stopwatch elapsed = new Stopwatch();
|
||||||
double lag = 0.0;
|
double lag = 0.0;
|
||||||
|
|
|
@ -130,7 +130,9 @@ void addControls(Example ex) {
|
||||||
|
|
||||||
// Don't add controls which don't work anyways (for simple examples)
|
// Don't add controls which don't work anyways (for simple examples)
|
||||||
if(examples.indexOf(ex) <= 1) return;
|
if(examples.indexOf(ex) <= 1) return;
|
||||||
|
VariableUpdates loop = (ex.loop as VariableUpdates);
|
||||||
|
|
||||||
|
// Update Speed Slider
|
||||||
group
|
group
|
||||||
..append(new LabelElement()
|
..append(new LabelElement()
|
||||||
..htmlFor = "update_speed"
|
..htmlFor = "update_speed"
|
||||||
|
@ -138,11 +140,11 @@ void addControls(Example ex) {
|
||||||
..append(new InputElement(type: "range")
|
..append(new InputElement(type: "range")
|
||||||
..id = "update_speed"
|
..id = "update_speed"
|
||||||
..min = "1"
|
..min = "1"
|
||||||
..max = "20"
|
..max = "50"
|
||||||
..value = "3"
|
..value = "3"
|
||||||
..step = "1"
|
..step = "1"
|
||||||
..onInput.listen((Event e) {
|
..onInput.listen((Event e) {
|
||||||
ex.loop;
|
loop.MS_PER_UPDATE = (1000 / int.parse((e.target as InputElement).value));
|
||||||
}));
|
}));
|
||||||
// querySelector('#reset').onClick.listen((e) => ex.loop.game.reset());
|
// querySelector('#reset').onClick.listen((e) => ex.loop.game.reset());
|
||||||
// querySelector('#plus').onClick.listen((e) => _changeGrid(-5));
|
// querySelector('#plus').onClick.listen((e) => _changeGrid(-5));
|
||||||
|
|
Loading…
Reference in a new issue