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

Unified Diff: sky/examples/game/lib/spritesheet.dart

Issue 1218593002: Move sky/examples to sky/sdk/lib/example, and code changes to support that change. Fixes T277. (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 side-by-side diff with in-line comments
Download patch
Index: sky/examples/game/lib/spritesheet.dart
diff --git a/sky/examples/game/lib/spritesheet.dart b/sky/examples/game/lib/spritesheet.dart
deleted file mode 100644
index 39bf503a28808d2883d9e8c3a096ab9b6996aad6..0000000000000000000000000000000000000000
--- a/sky/examples/game/lib/spritesheet.dart
+++ /dev/null
@@ -1,74 +0,0 @@
-part of sprites;
-
-/// A sprite sheet packs a number of smaller images into a single large image.
-///
-/// The placement of the smaller images are defined by a json file. The larger image and json file is typically created
-/// by a tool such as TexturePacker. The [SpriteSheet] class will take a reference to a larger image and a json string.
-/// From the image and the string the [SpriteSheet] creates a number of [Texture] objects. The names of the frames in
-/// the sprite sheet definition are used to reference the different textures.
-class SpriteSheet {
-
- Image _image;
- Map<String, Texture> _textures = new Map();
-
- /// Creates a new sprite sheet from an [_image] and a sprite sheet [jsonDefinition].
- ///
- /// var mySpriteSheet = new SpriteSheet(myImage, jsonString);
- SpriteSheet(this._image, String jsonDefinition) {
- assert(_image != null);
- assert(jsonDefinition != null);
-
- JsonDecoder decoder = new JsonDecoder();
- Map file = decoder.convert(jsonDefinition);
- assert(file != null);
-
- List frames = file["frames"];
-
- for (Map frameInfo in frames) {
- String fileName = frameInfo["filename"];
- Rect frame = _readJsonRect(frameInfo["frame"]);
- bool rotated = frameInfo["rotated"];
- bool trimmed = frameInfo["trimmed"];
- Rect spriteSourceSize = _readJsonRect(frameInfo["spriteSourceSize"]);
- Size sourceSize = _readJsonSize(frameInfo["sourceSize"]);
- Point pivot = _readJsonPoint(frameInfo["pivot"]);
-
- var texture = new Texture._fromSpriteFrame(_image, fileName, sourceSize, rotated, trimmed, frame,
- spriteSourceSize, pivot);
- _textures[fileName] = texture;
- }
- }
-
- Rect _readJsonRect(Map data) {
- num x = data["x"];
- num y = data["y"];
- num w = data["w"];
- num h = data["h"];
-
- return new Rect.fromLTRB(x.toDouble(), y.toDouble(), (x + w).toDouble(), (y + h).toDouble());
- }
-
- Size _readJsonSize(Map data) {
- num w = data["w"];
- num h = data["h"];
-
- return new Size(w.toDouble(), h.toDouble());
- }
-
- Point _readJsonPoint(Map data) {
- num x = data["x"];
- num y = data["y"];
-
- return new Point(x.toDouble(), y.toDouble());
- }
-
- /// The image used by the sprite sheet.
- ///
- /// var spriteSheetImage = mySpriteSheet.image;
- Image get image => _image;
-
- /// Returns a texture by its name.
- ///
- /// var myTexture = mySpriteSheet["example.png"];
- Texture operator [](String fileName) => _textures[fileName];
-}

Powered by Google App Engine
This is Rietveld 408576698