| OLD | NEW |
| 1 part of sprites; | 1 part of sprites; |
| 2 | 2 |
| 3 /// A texture represents a rectangular area of an image and is typically used to
draw a sprite to the screen. | 3 /// A texture represents a rectangular area of an image and is typically used to
draw a sprite to the screen. |
| 4 /// | 4 /// |
| 5 /// Normally you get a reference to a texture from a [SpriteSheet], but you can
also create one from an [Image]. | 5 /// Normally you get a reference to a texture from a [SpriteSheet], but you can
also create one from an [Image]. |
| 6 class Texture { | 6 class Texture { |
| 7 /// The image that this texture is a part of. | 7 /// The image that this texture is a part of. |
| 8 /// | 8 /// |
| 9 /// var textureImage = myTexture.image; | 9 /// var textureImage = myTexture.image; |
| 10 final Image image; | 10 final Image image; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 double y = position.y; | 80 double y = position.y; |
| 81 bool translate = (x != 0 || y != 0); | 81 bool translate = (x != 0 || y != 0); |
| 82 if (translate) { | 82 if (translate) { |
| 83 canvas.translate(x, y); | 83 canvas.translate(x, y); |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Draw the texture | 86 // Draw the texture |
| 87 if (rotated) { | 87 if (rotated) { |
| 88 // Calculate the rotated frame and spriteSourceSize | 88 // Calculate the rotated frame and spriteSourceSize |
| 89 Size originalFrameSize = frame.size; | 89 Size originalFrameSize = frame.size; |
| 90 Rect rotatedFrame = new Rect.fromPointAndSize(frame.upperLeft, new Size(or
iginalFrameSize.height, originalFrameSize.width)); | 90 Rect rotatedFrame = frame.topLeft & new Size(originalFrameSize.height, ori
ginalFrameSize.width); |
| 91 Point rotatedSpriteSourcePoint = new Point( | 91 Point rotatedSpriteSourcePoint = new Point( |
| 92 -spriteSourceSize.top - (spriteSourceSize.bottom - spriteSourceSize.to
p), | 92 -spriteSourceSize.top - (spriteSourceSize.bottom - spriteSourceSize.to
p), |
| 93 spriteSourceSize.left); | 93 spriteSourceSize.left); |
| 94 Rect rotatedSpriteSourceSize = new Rect.fromPointAndSize(rotatedSpriteSour
cePoint, new Size(originalFrameSize.height, originalFrameSize.width)); | 94 Rect rotatedSpriteSourceSize = rotatedSpriteSourcePoint & new Size(origina
lFrameSize.height, originalFrameSize.width); |
| 95 | 95 |
| 96 // Draw the rotated sprite | 96 // Draw the rotated sprite |
| 97 canvas.rotate(-Math.PI/2.0); | 97 canvas.rotate(-Math.PI/2.0); |
| 98 canvas.drawImageRect(image, rotatedFrame, rotatedSpriteSourceSize, paint); | 98 canvas.drawImageRect(image, rotatedFrame, rotatedSpriteSourceSize, paint); |
| 99 canvas.rotate(Math.PI/2.0); | 99 canvas.rotate(Math.PI/2.0); |
| 100 } else { | 100 } else { |
| 101 // Draw the sprite | 101 // Draw the sprite |
| 102 canvas.drawImageRect(image, frame, spriteSourceSize, paint); | 102 canvas.drawImageRect(image, frame, spriteSourceSize, paint); |
| 103 } | 103 } |
| 104 | 104 |
| 105 // Translate back | 105 // Translate back |
| 106 if (translate) { | 106 if (translate) { |
| 107 canvas.translate(-x, -y); | 107 canvas.translate(-x, -y); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 } | 110 } |
| OLD | NEW |