OLD | NEW |
---|---|
(Empty) | |
1 part of sprites; | |
2 | |
3 class SpriteSheet { | |
4 | |
5 Image _image; | |
6 Map<String, Texture> _textures = new Map(); | |
7 | |
8 SpriteSheet(this._image, String jsonDefinition) { | |
9 assert(_image != null); | |
10 assert(jsonDefinition != null); | |
11 | |
12 JsonDecoder decoder = new JsonDecoder(); | |
13 Map file = decoder.convert(jsonDefinition); | |
14 assert(file != null); | |
15 | |
16 List frames = file["frames"]; | |
17 | |
18 for (Map frameInfo in frames) { | |
19 String fileName = frameInfo["filename"]; | |
20 Rect frame = _readJsonRect(frameInfo["frame"]); | |
21 bool rotated = frameInfo["rotated"]; | |
22 bool trimmed = frameInfo["trimmed"]; | |
23 Rect spriteSourceSize = _readJsonRect(frameInfo["spriteSourceSize"]); | |
24 Size sourceSize = _readJsonSize(frameInfo["sourceSize"]); | |
25 Point pivot = _readJsonPoint(frameInfo["pivot"]); | |
26 | |
27 var texture = new Texture._fromSpriteFrame(_image, fileName, sourceSize, r otated, trimmed, frame, | |
28 spriteSourceSize, pivot); | |
29 _textures[fileName] = texture; | |
30 } | |
31 } | |
32 | |
33 Rect _readJsonRect(Map data) { | |
34 num x = data["x"]; | |
eseidel
2015/06/23 23:22:31
Do you mean to use num instead of int or double?
| |
35 num y = data["y"]; | |
36 num w = data["w"]; | |
37 num h = data["h"]; | |
38 | |
39 return new Rect.fromLTRB(x.toDouble(), y.toDouble(), (x + w).toDouble(), (y + h).toDouble()); | |
40 } | |
41 | |
42 Size _readJsonSize(Map data) { | |
43 num w = data["w"]; | |
44 num h = data["h"]; | |
45 | |
46 return new Size(w.toDouble(), h.toDouble()); | |
47 } | |
48 | |
49 Point _readJsonPoint(Map data) { | |
50 num x = data["x"]; | |
51 num y = data["y"]; | |
52 | |
53 return new Point(x.toDouble(), y.toDouble()); | |
54 } | |
55 | |
56 Image get image => _image; | |
57 | |
58 Texture operator [](String fileName) => _textures[fileName]; | |
59 } | |
OLD | NEW |