chore: Remove 1.8.0 deprecations (#2538)

Removes all the deprecated methods before 1.8.0 release.
This commit is contained in:
Lukas Klingsbo
2023-05-22 19:01:55 +02:00
committed by GitHub
parent 6e1d5466aa
commit 2d45d2be39
139 changed files with 1224 additions and 1084 deletions

View File

@ -2,14 +2,14 @@ import 'dart:math';
import 'package:flame/components.dart';
import 'package:flame/effects.dart';
import 'package:flame/events.dart';
import 'package:flame/extensions.dart';
import 'package:flame/game.dart';
import 'package:flame/input.dart';
import 'package:flame/palette.dart';
import 'package:flame/sprite.dart';
import 'package:flutter/material.dart';
class LookAtSmoothExample extends FlameGame with TapDetector {
class LookAtSmoothExample extends FlameGame {
static const description = 'This example demonstrates how a component can be '
'made to smoothly rotate towards a target using the angleTo method. '
'Tap anywhere to change the target point for both the choppers. '
@ -17,22 +17,20 @@ class LookAtSmoothExample extends FlameGame with TapDetector {
'oriented in the desired direction if the image is not facing the '
'correct direction.';
bool _isRotating = false;
final world = _TapWorld();
late final CameraComponent cameraComponent;
late SpriteAnimationComponent _chopper1;
late SpriteAnimationComponent _chopper2;
final CircleComponent _targetComponent = CircleComponent(
radius: 5,
anchor: Anchor.center,
paint: BasicPalette.black.paint(),
);
@override
Color backgroundColor() => const Color.fromARGB(255, 96, 145, 112);
@override
Future<void>? onLoad() async {
camera.viewport = FixedResolutionViewport(Vector2(640, 360));
Future<void> onLoad() async {
cameraComponent = CameraComponent(world: world);
addAll([cameraComponent, world]);
final spriteSheet = SpriteSheet(
image: await images.load('animations/chopper.png'),
srcSize: Vector2.all(48),
@ -40,63 +38,29 @@ class LookAtSmoothExample extends FlameGame with TapDetector {
_spawnChoppers(spriteSheet);
_spawnInfoText();
return super.onLoad();
}
@override
void onTapDown(TapDownInfo info) {
if (!_targetComponent.isMounted) {
add(_targetComponent);
}
// Ignore if choppers are already rotating.
if (!_isRotating) {
_isRotating = true;
_targetComponent.position = info.eventPosition.game;
_chopper1.add(
RotateEffect.by(
_chopper1.angleTo(_targetComponent.absolutePosition),
LinearEffectController(1),
onComplete: () => _isRotating = false,
),
);
_chopper2.add(
RotateEffect.by(
_chopper2.angleTo(_targetComponent.absolutePosition),
LinearEffectController(1),
onComplete: () => _isRotating = false,
),
);
}
super.onTapDown(info);
}
void _spawnChoppers(SpriteSheet spriteSheet) {
// Notice now the nativeAngle is set to pi because the chopper
// is facing in down/south direction in the original image.
add(
world.add(
_chopper1 = SpriteAnimationComponent(
nativeAngle: pi,
size: Vector2.all(64),
size: Vector2.all(128),
anchor: Anchor.center,
animation: spriteSheet.createAnimation(row: 0, stepTime: 0.05),
position: Vector2(size.x * 0.3, size.y * 0.5),
),
);
// This chopper does not use correct nativeAngle, hence using
// lookAt on it results in the sprite pointing in incorrect
// direction visually.
add(
world.add(
_chopper2 = SpriteAnimationComponent(
size: Vector2.all(64),
size: Vector2.all(128),
anchor: Anchor.center,
animation: spriteSheet.createAnimation(row: 0, stepTime: 0.05),
position: Vector2(size.x * 0.6, size.y * 0.5),
position: Vector2(0, 160),
),
);
}
@ -106,29 +70,63 @@ class LookAtSmoothExample extends FlameGame with TapDetector {
final shaded = TextPaint(
style: TextStyle(
color: BasicPalette.white.color,
fontSize: 20.0,
fontSize: 30.0,
shadows: const [
Shadow(offset: Offset(1, 1), blurRadius: 1),
],
),
);
add(
world.add(
TextComponent(
text: 'nativeAngle = pi',
textRenderer: shaded,
anchor: Anchor.center,
position: _chopper1.absolutePosition + Vector2(0, -50),
position: _chopper1.absolutePosition + Vector2(0, -70),
),
);
add(
world.add(
TextComponent(
text: 'nativeAngle = 0',
textRenderer: shaded,
anchor: Anchor.center,
position: _chopper2.absolutePosition + Vector2(0, -50),
position: _chopper2.absolutePosition + Vector2(0, -70),
),
);
}
}
class _TapWorld extends World with TapCallbacks {
bool _isRotating = false;
final CircleComponent _targetComponent = CircleComponent(
radius: 5,
anchor: Anchor.center,
paint: BasicPalette.black.paint(),
);
@override
void onTapDown(TapDownEvent event) {
if (!_targetComponent.isMounted) {
add(_targetComponent);
}
// Ignore if choppers are already rotating.
if (!_isRotating) {
_isRotating = true;
_targetComponent.position = event.localPosition;
final choppers = children.query<SpriteAnimationComponent>();
for (final chopper in choppers) {
chopper.add(
RotateEffect.by(
chopper.angleTo(_targetComponent.absolutePosition),
LinearEffectController(1),
onComplete: () => _isRotating = false,
),
);
}
}
}
}