| 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 texture that the sprite will render to screen. | 6 /// The texture that the sprite will render to screen. |
| 7 /// | 7 /// |
| 8 /// If the texture is null, the sprite will be rendered as a red square | 8 /// If the texture 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 Paint paint = new Paint(); | 96 Paint paint = new Paint(); |
| 97 paint.color = new Color.fromARGB((255.0*_opacity).toInt(), 255, 255, 255); | 97 paint.color = new Color.fromARGB((255.0*_opacity).toInt(), 255, 255, 255); |
| 98 if (colorOverlay != null) { | 98 if (colorOverlay != null) { |
| 99 paint.setColorFilter(new ColorFilter.mode(colorOverlay, TransferMode.src
ATop)); | 99 paint.setColorFilter(new ColorFilter.mode(colorOverlay, TransferMode.src
ATop)); |
| 100 } | 100 } |
| 101 if (transferMode != null) { | 101 if (transferMode != null) { |
| 102 paint.setTransferMode(transferMode); | 102 paint.setTransferMode(transferMode); |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Do actual drawing of the sprite | 105 // Do actual drawing of the sprite |
| 106 canvas.drawImageRect(texture.image, texture.frame, texture.spriteSourceSiz
e, paint); | 106 if (texture.rotated) { |
| 107 // Calculate the rotated frame and spriteSourceSize |
| 108 Size originalFrameSize = texture.frame.size; |
| 109 Rect rotatedFrame = new Rect.fromPointAndSize(texture.frame.upperLeft, n
ew Size(originalFrameSize.height, originalFrameSize.width)); |
| 110 Point rotatedSpriteSourcePoint = new Point( |
| 111 -texture.spriteSourceSize.top - (texture.spriteSourceSize.bottom - t
exture.spriteSourceSize.top), |
| 112 texture.spriteSourceSize.left); |
| 113 Rect rotatedSpriteSourceSize = new Rect.fromPointAndSize(rotatedSpriteSo
urcePoint, new Size(originalFrameSize.height, originalFrameSize.width)); |
| 114 |
| 115 // Draw the rotated sprite |
| 116 canvas.rotate(-Math.PI/2.0); |
| 117 canvas.drawImageRect(texture.image, rotatedFrame, rotatedSpriteSourceSiz
e, paint); |
| 118 } else { |
| 119 // Draw the sprite |
| 120 canvas.drawImageRect(texture.image, texture.frame, texture.spriteSourceS
ize, paint); |
| 121 } |
| 107 } else { | 122 } else { |
| 108 // Paint a red square for missing texture | 123 // Paint a red square for missing texture |
| 109 canvas.drawRect(new Rect.fromLTRB(0.0, 0.0, size.width, size.height), | 124 canvas.drawRect(new Rect.fromLTRB(0.0, 0.0, size.width, size.height), |
| 110 new Paint()..color = const Color.fromARGB(255, 255, 0, 0)); | 125 new Paint()..color = const Color.fromARGB(255, 255, 0, 0)); |
| 111 } | 126 } |
| 112 canvas.restore(); | 127 canvas.restore(); |
| 113 } | 128 } |
| 114 } | 129 } |
| OLD | NEW |