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

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

Issue 1212073002: Improved documentation for SkyGames and support for rotated textures (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
« no previous file with comments | « sky/examples/game/lib/sprite.dart ('k') | sky/examples/game/lib/texture.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 part of sprites; 1 part of sprites;
2 2
3 /// A sprite sheet packs a number of smaller images into a single large image.
4 ///
5 /// The placement of the smaller images are defined by a json file. The larger i mage and json file is typically created
6 /// by a tool such as TexturePacker. The [SpriteSheet] class will take a referen ce to a larger image and a json string.
7 /// From the image and the string the [SpriteSheet] creates a number of [Texture ] objects. The names of the frames in
8 /// the sprite sheet definition are used to reference the different textures.
3 class SpriteSheet { 9 class SpriteSheet {
4 10
5 Image _image; 11 Image _image;
6 Map<String, Texture> _textures = new Map(); 12 Map<String, Texture> _textures = new Map();
7 13
14 /// Creates a new sprite sheet from an [_image] and a sprite sheet [jsonDefini tion].
15 ///
16 /// var mySpriteSheet = new SpriteSheet(myImage, jsonString);
8 SpriteSheet(this._image, String jsonDefinition) { 17 SpriteSheet(this._image, String jsonDefinition) {
9 assert(_image != null); 18 assert(_image != null);
10 assert(jsonDefinition != null); 19 assert(jsonDefinition != null);
11 20
12 JsonDecoder decoder = new JsonDecoder(); 21 JsonDecoder decoder = new JsonDecoder();
13 Map file = decoder.convert(jsonDefinition); 22 Map file = decoder.convert(jsonDefinition);
14 assert(file != null); 23 assert(file != null);
15 24
16 List frames = file["frames"]; 25 List frames = file["frames"];
17 26
(...skipping 28 matching lines...) Expand all
46 return new Size(w.toDouble(), h.toDouble()); 55 return new Size(w.toDouble(), h.toDouble());
47 } 56 }
48 57
49 Point _readJsonPoint(Map data) { 58 Point _readJsonPoint(Map data) {
50 num x = data["x"]; 59 num x = data["x"];
51 num y = data["y"]; 60 num y = data["y"];
52 61
53 return new Point(x.toDouble(), y.toDouble()); 62 return new Point(x.toDouble(), y.toDouble());
54 } 63 }
55 64
65 /// The image used by the sprite sheet.
66 ///
67 /// var spriteSheetImage = mySpriteSheet.image;
56 Image get image => _image; 68 Image get image => _image;
57 69
70 /// Returns a texture by its name.
71 ///
72 /// var myTexture = mySpriteSheet["example.png"];
58 Texture operator [](String fileName) => _textures[fileName]; 73 Texture operator [](String fileName) => _textures[fileName];
59 } 74 }
OLDNEW
« no previous file with comments | « sky/examples/game/lib/sprite.dart ('k') | sky/examples/game/lib/texture.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698