mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
Migrate examples back, change to monorepo (#701)
This commit is contained in:
71
examples/lib/stories/animations/basic.dart
Normal file
71
examples/lib/stories/animations/basic.dart
Normal 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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user