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

Side by Side Diff: sky/examples/game/lib/sprite.dart

Issue 1179413009: Adds basic touch handling to sprites and optimizes transformations (Closed) Base URL: git@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
1 part of sprites; 1 part of sprites;
2 2
3 // TODO: Actually draw images 3 // TODO: Actually draw images
4 4
5 class Sprite extends NodeWithSize { 5 class Sprite extends NodeWithSize {
6 6
7 Image _image; 7 Image _image;
8 bool constrainProportions = false; 8 bool constrainProportions = false;
9 double _opacity = 1.0; 9 double _opacity = 1.0;
10 Color colorOverlay; 10 Color colorOverlay;
11 TransferMode transferMode; 11 TransferMode transferMode;
12 12
13 Sprite() { 13 Sprite() {
14 } 14 }
15 15
16 Sprite.withImage(Image image) { 16 Sprite.withImage(Image image) {
17 pivot = new Point(0.5, 0.5); 17 pivot = new Point(0.5, 0.5);
18 size = new Size(image.width.toDouble(), image.height.toDouble()); 18 size = new Size(image.width.toDouble(), image.height.toDouble());
19 _image = image; 19 _image = image;
20 } 20 }
21 21
22 double get opacity => _opacity; 22 double get opacity => _opacity;
23 23
24 void set opacity(double opacity) { 24 void set opacity(double opacity) {
25 assert(opacity != null);
25 assert(opacity >= 0.0 && opacity <= 1.0); 26 assert(opacity >= 0.0 && opacity <= 1.0);
26 _opacity = opacity; 27 _opacity = opacity;
27 } 28 }
28 29
29 void paint(PictureRecorder canvas) { 30 void paint(PictureRecorder canvas) {
30 canvas.save(); 31 canvas.save();
31 32
32 // Account for pivot point 33 // Account for pivot point
33 applyTransformForPivot(canvas); 34 applyTransformForPivot(canvas);
34 35
(...skipping 29 matching lines...) Expand all
64 canvas.drawImage(_image, 0.0, 0.0, paint); 65 canvas.drawImage(_image, 0.0, 0.0, paint);
65 } 66 }
66 else { 67 else {
67 // Paint a red square for missing texture 68 // Paint a red square for missing texture
68 canvas.drawRect(new Rect.fromLTRB(0.0, 0.0, size.width, size.height), 69 canvas.drawRect(new Rect.fromLTRB(0.0, 0.0, size.width, size.height),
69 new Paint()..color = const Color.fromARGB(255, 255, 0, 0)); 70 new Paint()..color = const Color.fromARGB(255, 255, 0, 0));
70 } 71 }
71 canvas.restore(); 72 canvas.restore();
72 } 73 }
73 } 74 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698