scale method

  1. @override
Future<void> scale(
  1. num scale
)
override

Scales animation.

Implementation

@override
Future<void> scale(num scale) async {
  assert(scale > 0);

  print('\n--scale'
      '\n\tsource: `$sourcePath`'
      '\n\tscale: $scale'
      '\n');

  // 1) Scale texture.
  var step = 1;
  resetCurrentIndent();
  {
    final p = pathToFileTexture;
    print('$currentIndent$step) Scaling texture `$p` to $scale...');

    final file = File(p);
    final bytes = file.readAsBytesSync();
    final image = decodeImage(bytes)!;
    final width = image.width * scale;
    final height = image.height * scale;
    final scaled = copyResize(
      image,
      width: width.toInt(),
      height: height.toInt(),
      interpolation: Interpolation.nearest,
    );

    final encoded = encodePng(scaled);
    file.writeAsBytesSync(encoded, flush: true);

    /* \todo Add a compress to WEBP format.
    \see https://pub.dev/packages/flutter_image_compress
    final compressed = await FlutterImageCompress.compressWithList(
      image.getBytes(),
      minWidth: width.toInt(),
      minHeight: height.toInt(),
      quality: 100,
      format: CompressFormat.webp,
      keepExif: true,
    );
    file.writeAsBytesSync(compressed, flush: true);
    */

    print('$currentIndent\tSuccess scaling texture `$p` to $scale.');
  }

  // 2) Scale atlas.
  ++step;
  resetCurrentIndent();
  {
    final p = pathToFileAtlas;
    print('$currentIndent$step) Scaling atlas `$p` to $scale...');

    final file = File(p);
    final textureAtlas = SpineTextureAtlas(file);
    textureAtlas.scaleAndSave(scale);

    print('$currentIndent\tSuccess scaling atlas `$p` to $scale.');
  }

  // 3) Scale skeleton.
  ++step;
  resetCurrentIndent();
  {
    final p = pathToFileSkeleton;
    print('$currentIndent$step) Scaling skeleton `$p` to $scale...');

    final file = File(p);
    final skeleton = SpineSkeletonJson(file);
    final scaled = skeleton.scale(scale);
    skeleton.save(scaled);

    print('$currentIndent\tSuccess scaling skeleton `$p` to $scale.');
  }
}