1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_sprites/flutter_sprites.dart';
AssetBundle _initBundle() {
if (rootBundle != null)
return rootBundle;
return new NetworkAssetBundle(Uri.base);
}
final AssetBundle _bundle = _initBundle();
ImageMap _images;
SpriteSheet _spriteSheet;
final ThemeData _theme = new ThemeData(
brightness: ThemeBrightness.light,
primarySwatch: Colors.purple
);
main() async {
_images = new ImageMap(_bundle);
await _images.load([
'assets/sprites.png'
]);
String json = await _bundle.loadString('assets/sprites.json');
_spriteSheet = new SpriteSheet(_images['assets/sprites.png'], json);
runApp(new MaterialApp(
title: 'Test drawAtlas',
theme: _theme,
routes: {
'/': (RouteArguments args) {
return new SpriteWidget(
new TestDrawAtlas(),
SpriteBoxTransformMode.fixedWidth
);
}
}
));
}
class TestDrawAtlas extends NodeWithSize {
TestDrawAtlas() : super(new Size(1024.0, 1024.0)) {
}
void paint(PaintingCanvas canvas) {
List<RSTransform> transforms = [
new RSTransform(1.0, 0.0, 100.0, 100.0)
];
List<Rect> rects = [
_spriteSheet["ship.png"].frame
];
List<Color> colors = [
new Color(0xffffffff)
];
canvas.drawAtlas(
_spriteSheet.image,
transforms,
rects,
colors,
TransferMode.src,
null,
new Paint()
..filterQuality = FilterQuality.low
..isAntiAlias = false
);
}
}