fix: Remove deprecations for 1.10.0 (#2809)

Removed deprecations for 1.10.0 and fixes some small unreleased regressions found when going through the examples.
This commit is contained in:
Lukas Klingsbo
2023-10-11 15:57:25 +02:00
committed by GitHub
parent 97fff0ed2b
commit 5b67b8f14a
96 changed files with 824 additions and 4925 deletions

View File

@ -2,48 +2,28 @@ import 'dart:ui';
import 'package:examples/commons/ember.dart';
import 'package:flame/components.dart';
import 'package:flame/events.dart';
import 'package:flame/game.dart';
import 'package:flame/input.dart';
class BasicAnimationsExample extends FlameGame with TapDetector {
class BasicAnimationsExample extends FlameGame {
static const description = '''
Basic example of `SpriteAnimation`s use in Flame's `FlameGame`\n\n
The snippet shows how an animation can be loaded and added to the game
```
class MyGame extends FlameGame {
@override
Future<void> onLoad() async {
final animation = await loadSpriteAnimation(
'animations/chopper.png',
SpriteAnimationData.sequenced(
amount: 4,
textureSize: Vector2.all(48),
stepTime: 0.15,
),
);
final animationComponent = SpriteAnimationComponent(
animation: animation,
size: Vector2.all(100.0),
);
add(animationComponent);
}
}
```
Basic example of how to use `SpriteAnimation`s in Flame's.
On this example, click or touch anywhere on the screen to dynamically add
In this example, click or touch anywhere on the screen to dynamically add
animations.
''';
BasicAnimationsExample() : super(world: BasicAnimationsWorld());
}
class BasicAnimationsWorld extends World with TapCallbacks, HasGameReference {
late Image creature;
@override
Future<void> onLoad() async {
creature = await images.load('animations/creature.png');
creature = await game.images.load('animations/creature.png');
final animation = await loadSpriteAnimation(
final animation = await game.loadSpriteAnimation(
'animations/chopper.png',
SpriteAnimationData.sequenced(
amount: 4,
@ -55,24 +35,25 @@ class BasicAnimationsExample extends FlameGame with TapDetector {
final spriteSize = Vector2.all(100.0);
final animationComponent = SpriteAnimationComponent(
animation: animation,
position: Vector2(-spriteSize.x, 0),
size: spriteSize,
anchor: Anchor.center,
);
animationComponent.x = size.x / 2 - spriteSize.x;
animationComponent.y = spriteSize.y;
final reversedAnimationComponent = SpriteAnimationComponent(
animation: animation.reversed(),
position: Vector2(spriteSize.x, 0),
size: spriteSize,
anchor: Anchor.center,
);
reversedAnimationComponent.x = size.x / 2;
reversedAnimationComponent.y = spriteSize.y;
add(animationComponent);
add(reversedAnimationComponent);
add(Ember()..position = size / 2);
add(Ember());
}
void addAnimation(Vector2 position) {
@override
void onTapDown(TapDownEvent event) {
final size = Vector2(291, 178);
final animationComponent = SpriteAnimationComponent.fromFrameData(
@ -84,16 +65,12 @@ class BasicAnimationsExample extends FlameGame with TapDetector {
stepTime: 0.15,
loop: false,
),
position: event.localPosition,
anchor: Anchor.center,
size: size,
removeOnFinish: true,
);
animationComponent.position = position - size / 2;
add(animationComponent);
}
@override
void onTapDown(TapDownInfo info) {
addAnimation(info.eventPosition.game);
}
}