OLD | NEW |
1 part of sprites; | 1 part of sprites; |
2 | 2 |
3 /// A Sprite is a [Node] that renders a bitmap image to the screen. | 3 /// A Sprite is a [Node] that renders a bitmap image to the screen. |
4 class Sprite extends NodeWithSize { | 4 class Sprite extends NodeWithSize { |
5 | 5 |
6 /// The image that the sprite will render to screen. | 6 /// The image that the sprite will render to screen. |
7 /// | 7 /// |
8 /// If the image is null, the sprite will be rendered as a red square | 8 /// If the image is null, the sprite will be rendered as a red square |
9 /// marking the bounds of the sprite. | 9 /// marking the bounds of the sprite. |
10 /// | 10 /// |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 /// | 43 /// |
44 /// mySprite.opacity = 0.5; | 44 /// mySprite.opacity = 0.5; |
45 double get opacity => _opacity; | 45 double get opacity => _opacity; |
46 | 46 |
47 void set opacity(double opacity) { | 47 void set opacity(double opacity) { |
48 assert(opacity != null); | 48 assert(opacity != null); |
49 assert(opacity >= 0.0 && opacity <= 1.0); | 49 assert(opacity >= 0.0 && opacity <= 1.0); |
50 _opacity = opacity; | 50 _opacity = opacity; |
51 } | 51 } |
52 | 52 |
53 void paint(PictureRecorder canvas) { | 53 void paint(RenderCanvas canvas) { |
54 canvas.save(); | 54 canvas.save(); |
55 | 55 |
56 // Account for pivot point | 56 // Account for pivot point |
57 applyTransformForPivot(canvas); | 57 applyTransformForPivot(canvas); |
58 | 58 |
59 if (image != null && image.width > 0 && image.height > 0) { | 59 if (image != null && image.width > 0 && image.height > 0) { |
60 | 60 |
61 double scaleX = size.width/image.width; | 61 double scaleX = size.width/image.width; |
62 double scaleY = size.height/image.height; | 62 double scaleY = size.height/image.height; |
63 | 63 |
(...skipping 24 matching lines...) Expand all Loading... |
88 canvas.drawImage(image, 0.0, 0.0, paint); | 88 canvas.drawImage(image, 0.0, 0.0, paint); |
89 } | 89 } |
90 else { | 90 else { |
91 // Paint a red square for missing texture | 91 // Paint a red square for missing texture |
92 canvas.drawRect(new Rect.fromLTRB(0.0, 0.0, size.width, size.height), | 92 canvas.drawRect(new Rect.fromLTRB(0.0, 0.0, size.width, size.height), |
93 new Paint()..color = const Color.fromARGB(255, 255, 0, 0)); | 93 new Paint()..color = const Color.fromARGB(255, 255, 0, 0)); |
94 } | 94 } |
95 canvas.restore(); | 95 canvas.restore(); |
96 } | 96 } |
97 } | 97 } |
OLD | NEW |