Migrate examples back, change to monorepo (#701)

This commit is contained in:
Luan Nico
2021-03-12 09:24:50 -05:00
committed by GitHub
parent d3e8b87ee6
commit 769bb711c3
334 changed files with 2283 additions and 3279 deletions

View File

@ -0,0 +1,71 @@
import 'dart:ui';
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame/gestures.dart';
import 'package:flutter/gestures.dart' show TapDownDetails;
class BasicAnimations extends BaseGame with TapDetector {
Image chopper;
Image creature;
SpriteAnimation animation;
@override
Future<void> onLoad() async {
chopper = await images.load('animations/chopper.png');
creature = await images.load('animations/creature.png');
animation = SpriteAnimation.fromFrameData(
chopper,
SpriteAnimationData.sequenced(
amount: 4,
textureSize: Vector2.all(48),
stepTime: 0.15,
),
);
final spriteSize = Vector2.all(100.0);
final animationComponent2 = SpriteAnimationComponent(
animation: animation,
size: spriteSize,
);
animationComponent2.x = size.x / 2 - spriteSize.x;
animationComponent2.y = spriteSize.y;
final reversedAnimationComponent = SpriteAnimationComponent(
animation: animation.reversed(),
size: spriteSize,
);
reversedAnimationComponent.x = size.x / 2;
reversedAnimationComponent.y = spriteSize.y;
add(animationComponent2);
add(reversedAnimationComponent);
}
void addAnimation(Vector2 position) {
final size = Vector2(291, 178);
final animationComponent = SpriteAnimationComponent.fromFrameData(
creature,
SpriteAnimationData.sequenced(
amount: 18,
amountPerRow: 10,
textureSize: size,
stepTime: 0.15,
loop: false,
),
size: size,
removeOnFinish: true,
);
animationComponent.position = position;
animationComponent.position = animationComponent.position - size / 2;
add(animationComponent);
}
@override
void onTapDown(TapDownDetails evt) {
addAnimation(Vector2(evt.globalPosition.dx, evt.globalPosition.dy));
}
}