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. |
| 4 /// |
| 5 /// Normally you get a reference to a texture from a [SpriteSheet], but you can
also create one from an [Image]. |
3 class Texture { | 6 class Texture { |
| 7 /// The image that this texture is a part of. |
| 8 /// |
| 9 /// var textureImage = myTexture.image; |
4 final Image image; | 10 final Image image; |
| 11 |
| 12 /// The logical size of the texture, before being trimmed by the texture packe
r. |
| 13 /// |
| 14 /// var textureSize = myTexture.size; |
5 final Size size; | 15 final Size size; |
| 16 |
| 17 /// The name of the image acts as a tag when acquiring a reference to it. |
| 18 /// |
| 19 /// myTexture.name = "new_texture_name"; |
6 String name; | 20 String name; |
| 21 |
| 22 /// The texture was rotated 90 degrees when being packed into a sprite sheet. |
| 23 /// |
| 24 /// if (myTexture.rotated) drawRotated(); |
7 final bool rotated; | 25 final bool rotated; |
| 26 |
| 27 /// The texture was trimmed when being packed into a sprite sheet. |
| 28 /// |
| 29 /// bool trimmed = myTexture.trimmed |
8 final bool trimmed; | 30 final bool trimmed; |
9 | 31 |
10 Rect frame; | 32 /// The frame of the trimmed texture inside the image. |
11 Rect spriteSourceSize; | 33 /// |
| 34 /// Rect frame = myTexture.frame; |
| 35 final Rect frame; |
12 | 36 |
| 37 /// The offset and size of the trimmed texture inside the image. |
| 38 /// |
| 39 /// Position represents the offset from the logical [size], the size of the re
ct represents the size of the trimmed |
| 40 /// texture. |
| 41 /// |
| 42 /// Rect spriteSourceSize = myTexture.spriteSourceSize; |
| 43 final Rect spriteSourceSize; |
| 44 |
| 45 /// The default pivot point for this texture. When creating a [Sprite] from th
e texture, this is the pivot point that |
| 46 /// will be used. |
| 47 /// |
| 48 /// myTexture.pivot = new Point(0.5, 0.5); |
13 Point pivot; | 49 Point pivot; |
14 | 50 |
| 51 /// Creates a new texture from an [Image] object. |
| 52 /// |
| 53 /// var myTexture = new Texture(myImage); |
15 Texture(Image image) : | 54 Texture(Image image) : |
16 size = new Size(image.width.toDouble(), image.height.toDouble()), | 55 size = new Size(image.width.toDouble(), image.height.toDouble()), |
17 image = image, | 56 image = image, |
18 trimmed = false, | 57 trimmed = false, |
19 rotated = false, | 58 rotated = false, |
20 frame = new Rect.fromLTRB(0.0, 0.0, image.width.toDouble(), image.height.toD
ouble()), | 59 frame = new Rect.fromLTRB(0.0, 0.0, image.width.toDouble(), image.height.toD
ouble()), |
21 spriteSourceSize = new Rect.fromLTRB(0.0, 0.0, image.width.toDouble(), image
.height.toDouble()), | 60 spriteSourceSize = new Rect.fromLTRB(0.0, 0.0, image.width.toDouble(), image
.height.toDouble()), |
22 pivot = new Point(0.5, 0.5); | 61 pivot = new Point(0.5, 0.5); |
23 | 62 |
24 | 63 |
25 Texture._fromSpriteFrame(this.image, this.name, this.size, this.rotated, this.
trimmed, this.frame, | 64 Texture._fromSpriteFrame(this.image, this.name, this.size, this.rotated, this.
trimmed, this.frame, |
26 this.spriteSourceSize, this.pivot) { | 65 this.spriteSourceSize, this.pivot) { |
27 } | 66 } |
28 | 67 |
29 Texture textureFromRect(Rect rect, Point offset, bool rotated) { | 68 // Texture textureFromRect(Rect rect, [String name = null]) { |
30 // TODO: Implement this | 69 // assert(rect != null); |
31 return null; | 70 // Rect frame = new Rect.fromLTRB(); |
32 } | 71 // return new Texture._fromSpriteFrame(image, name, rect.size, false, false,
); |
| 72 // } |
33 } | 73 } |
OLD | NEW |