browserloops-examples/lib/src/02-AnimationFrameWhile.dart

32 lines
765 B
Dart
Raw Normal View History

2018-07-20 09:58:11 +00:00
import 'dart:html';
import 'package:browserloop/game/Game.dart';
import 'package:browserloop/game/LoopExample.dart';
/// The most basic update loop possible.
///
/// Note that this is technically cheating since it is using
/// animationFrames to improve browser performance for the examples in the
/// blog post. The real, actual simplest code is in file 01-WhileLoop.dart
class WhileLoop implements LoopExample {
Game game;
num id;
WhileLoop(Game this.game) {
window.requestAnimationFrame(eventloop);
}
void eventloop(num time) {
game.update();
game.draw();
id = window.requestAnimationFrame(eventloop);
}
void stop() {
window.cancelAnimationFrame(id);
}
void start() {
window.requestAnimationFrame(eventloop);
}
}