SpriteSheet constructor
Creates a new sprite sheet from an _image
and a sprite sheet jsonDefinition
.
var mySpriteSheet = new SpriteSheet(myImage, jsonString);
Implementation
SpriteSheet(this._image, String jsonDefinition) {
assert(_image != null);
assert(jsonDefinition != null);
JsonDecoder decoder = new JsonDecoder();
Map<dynamic, dynamic> file = decoder.convert(jsonDefinition);
assert(file != null);
List<dynamic> frames = file["frames"];
for (Map<dynamic, dynamic> 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"]);
Offset pivot = _readJsonPoint(frameInfo["pivot"]);
SpriteTexture texture = new SpriteTexture._fromSpriteFrame(_image, fileName, sourceSize, rotated, trimmed, frame,
spriteSourceSize, pivot);
_textures[fileName] = texture;
}
}