OLD | NEW |
(Empty) | |
| 1 import 'dart:sky'; |
| 2 import 'lib/game.dart'; |
| 3 |
| 4 int numFrames = 0; |
| 5 double lastTimeStamp = null; |
| 6 |
| 7 PictureRecorder canvas; |
| 8 |
| 9 GameWorld root; |
| 10 |
| 11 void beginFrame(double timeStamp) { |
| 12 // Calculate the time between frames in seconds |
| 13 if (lastTimeStamp == null) lastTimeStamp = timeStamp; |
| 14 double delta = (timeStamp - lastTimeStamp) / 1000; |
| 15 lastTimeStamp = timeStamp; |
| 16 |
| 17 // Count the number of frames we've been running |
| 18 numFrames += 1; |
| 19 |
| 20 // Print frame rate |
| 21 if (numFrames % 60 == 0) print("delta: ${delta} fps: ${1.0/delta}"); |
| 22 |
| 23 // Create a canvas to draw into |
| 24 canvas = new PictureRecorder(view.width, view.height); |
| 25 |
| 26 // Update all the sprites |
| 27 root.update(delta); |
| 28 |
| 29 // Draw all the sprites |
| 30 root.visit(canvas); |
| 31 |
| 32 // Output the image to the screen |
| 33 view.picture = canvas.endRecording(); |
| 34 view.scheduleFrame(); |
| 35 } |
| 36 |
| 37 void main() { |
| 38 |
| 39 root = new GameWorld(view.width, view.height); |
| 40 |
| 41 for (int i = 0; i < 50; i++) { |
| 42 root.addAsteroid(10.0); |
| 43 } |
| 44 |
| 45 for (int i = 0; i < 50; i++) { |
| 46 root.addAsteroid(20.0); |
| 47 } |
| 48 |
| 49 view.setBeginFrameCallback(beginFrame); |
| 50 view.scheduleFrame(); |
| 51 } |
OLD | NEW |