Luan PR suggestions

This commit is contained in:
Erick Zanardo
2020-09-29 17:53:47 -03:00
parent 08e89394c4
commit ebf05e0ca3
3 changed files with 20 additions and 19 deletions

View File

@ -9,7 +9,6 @@ import 'dart:ui';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Flame.images.loadAll(['creature.png', 'chopper.png']);
final Size size = await Flame.util.initialDimensions();
final game = MyGame(size);
@ -23,8 +22,8 @@ class MyGame extends BaseGame with TapDetector {
@override
Future<void> onLoad() async {
chopper = await Flame.images.load('chopper.png');
creature = await Flame.images.load('creature.png');
chopper = await images.load('chopper.png');
creature = await images.load('creature.png');
animation = SpriteAnimation.sequenced(
chopper,
@ -57,20 +56,11 @@ class MyGame extends BaseGame with TapDetector {
animationComponent.y = y - textureHeight / 2;
add(animationComponent);
}
@override
void onTapDown(TapDownDetails evt) {
addAnimation(evt.globalPosition.dx, evt.globalPosition.dy);
}
MyGame(Size screenSize) {
size = screenSize;
const s = 100.0;
final animationComponent = SpriteAnimationComponent(s, s, animation);
animationComponent.x = size.width / 2 - s;
animationComponent.y = s;
final animationComponent2 = SpriteAnimationComponent(s, s, animation);
animationComponent2.x = size.width / 2 - s;
animationComponent2.y = s;
final reversedAnimationComponent = SpriteAnimationComponent(
s,
@ -80,7 +70,16 @@ class MyGame extends BaseGame with TapDetector {
reversedAnimationComponent.x = size.width / 2;
reversedAnimationComponent.y = s;
add(animationComponent);
add(animationComponent2);
add(reversedAnimationComponent);
}
@override
void onTapDown(TapDownDetails evt) {
addAnimation(evt.globalPosition.dx, evt.globalPosition.dy);
}
MyGame(Size screenSize) {
size = screenSize;
}
}

View File

@ -17,7 +17,7 @@ class MyGame extends BaseGame {
@override
Future<void> onLoad() async {
final image = await Flame.images.load('chopper.png');
final image = await images.load('chopper.png');
final animation = await SpriteAnimation.fromAsepriteData(
image,
'chopper.json',

View File

@ -18,8 +18,10 @@ class Images {
Image fromCache(String fileName) {
final image = _loadedFiles[fileName];
assert(image?.loadedImage != null,
'Tried to access an inexistent entry on cache "$fileName"');
assert(
image?.loadedImage != null,
'Tried to access an inexistent entry on cache "$fileName", make sure to use the load method before accessing a file on the cache',
);
return image.loadedImage;
}