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

Side by Side 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, 6 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 unified diff | Download patch
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698