parseAtlasXml method
void
parseAtlasXml(
- XmlDocument atlasXml
Parses the provided XmlDocument and constructs the atlas.
Implementation
void parseAtlasXml(xml.XmlDocument atlasXml) {
var scale = _atlasTexture!.scale;
var region = GRect();
var frame = GRect();
final pivots = <String?, GPoint>{};
final nodeList = atlasXml.findAllElements('SubTexture');
for (var subTexture in nodeList) {
var name = subTexture.getAttribute('name');
var x = _attrDouble(subTexture, 'x') / scale! * _atlasXmlRatio;
var y = _attrDouble(subTexture, 'y') / scale * _atlasXmlRatio;
var width = _attrDouble(subTexture, 'width') / scale * _atlasXmlRatio;
var height = _attrDouble(subTexture, 'height') / scale * _atlasXmlRatio;
var frameX = _attrDouble(subTexture, 'frameX') / scale * _atlasXmlRatio;
var frameY = _attrDouble(subTexture, 'frameY') / scale * _atlasXmlRatio;
var frameWidth =
_attrDouble(subTexture, 'frameWidth') / scale * _atlasXmlRatio;
var frameHeight =
_attrDouble(subTexture, 'frameHeight') / scale * _atlasXmlRatio;
var pivotX = _attrDouble(subTexture, 'pivotX',
defaultValue: _attrDouble(subTexture, 'anchorX'));
var pivotY = _attrDouble(subTexture, 'pivotY',
defaultValue: _attrDouble(subTexture, 'anchorY'));
pivotX /= scale * _atlasXmlRatio;
pivotY /= scale * _atlasXmlRatio;
var rotated = _attrBoolean(subTexture, 'rotated', defaultValue: false);
region.setTo(x, y, width, height);
frame.setTo(frameX, frameY, frameWidth, frameHeight);
if (frameWidth > 0 && frameHeight > 0) {
addRegion(name, region, frame, rotated!);
} else {
addRegion(name, region, null, rotated!);
}
if (pivotX != 0 || pivotY != 0) {
/// image bind pivot point to texture!
pivots[name] = GPoint(pivotX, pivotY);
}
}
}