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(); |
+} |