Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Unified Diff: sky/examples/game/main.dart

Issue 1161023006: Adds basic support for images in game example (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sky/examples/game/main.dart
diff --git a/sky/examples/game/main.dart b/sky/examples/game/main.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9123c834beab6f7c9bd86c240dbb273bbb2ad208
--- /dev/null
+++ b/sky/examples/game/main.dart
@@ -0,0 +1,51 @@
+import 'dart:sky';
+import 'lib/game.dart';
+
+int numFrames = 0;
+double lastTimeStamp = null;
+
+PictureRecorder canvas;
+
+GameWorld root;
+
+void beginFrame(double timeStamp) {
+ // Calculate the time between frames in seconds
+ if (lastTimeStamp == null) lastTimeStamp = timeStamp;
+ double delta = (timeStamp - lastTimeStamp) / 1000;
+ lastTimeStamp = timeStamp;
+
+ // Count the number of frames we've been running
+ numFrames += 1;
+
+ // Print frame rate
+ if (numFrames % 60 == 0) print("delta: ${delta} fps: ${1.0/delta}");
+
+ // Create a canvas to draw into
+ canvas = new PictureRecorder(view.width, view.height);
+
+ // Update all the sprites
+ root.update(delta);
+
+ // Draw all the sprites
+ root.visit(canvas);
+
+ // Output the image to the screen
+ view.picture = canvas.endRecording();
+ view.scheduleFrame();
+}
+
+void main() {
+
+ root = new GameWorld(view.width, view.height);
+
+ for (int i = 0; i < 50; i++) {
+ root.addAsteroid(10.0);
+ }
+
+ for (int i = 0; i < 50; i++) {
+ root.addAsteroid(20.0);
+ }
+
+ view.setBeginFrameCallback(beginFrame);
+ view.scheduleFrame();
+}

Powered by Google App Engine
This is Rietveld 408576698