mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 04:18:25 +08:00
Refactored ScaleEffect to the new effects engine (#1123)
* Scale effect * Scale effect should affect scale... * Add ScaleEffect example * Added `ScaleEffect` * Fix analyze issue * Fix ScaleEffect tests
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame/effects.dart';
|
||||
import 'package:flame/extensions.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flame/input.dart';
|
||||
import 'package:flame/palette.dart';
|
||||
import 'package:flame/src/effects2/scale_effect.dart'; // ignore: implementation_imports
|
||||
import 'package:flame/src/effects2/standard_effect_controller.dart'; // ignore: implementation_imports
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../commons/square_component.dart';
|
||||
@ -12,8 +13,8 @@ class ScaleEffectExample extends FlameGame with TapDetector {
|
||||
static const String description = '''
|
||||
The `ScaleEffect` scales up the canvas before drawing the components and its
|
||||
children.
|
||||
In this example you can tap the screen and the component will scale up or down,
|
||||
depending on its current state.
|
||||
In this example you can tap the screen and the component will scale up or
|
||||
down, depending on its current state.
|
||||
''';
|
||||
|
||||
late SquareComponent square;
|
||||
@ -22,26 +23,28 @@ class ScaleEffectExample extends FlameGame with TapDetector {
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
square = SquareComponent()
|
||||
..position.setValues(200, 200)
|
||||
..anchor = Anchor.center;
|
||||
square.paint = BasicPalette.white.paint()..style = PaintingStyle.stroke;
|
||||
square = SquareComponent(
|
||||
position: Vector2.all(200),
|
||||
paint: BasicPalette.white.paint()..style = PaintingStyle.stroke,
|
||||
);
|
||||
final childSquare = SquareComponent(position: Vector2.all(70), size: 20);
|
||||
|
||||
square.add(childSquare);
|
||||
add(square);
|
||||
}
|
||||
|
||||
@override
|
||||
void onTap() {
|
||||
final s = grow ? 3.0 : 1.0;
|
||||
final s = grow ? 300.0 : 100.0;
|
||||
|
||||
grow = !grow;
|
||||
|
||||
square.add(
|
||||
ScaleEffect(
|
||||
scale: Vector2.all(s),
|
||||
speed: 2.0,
|
||||
curve: Curves.linear,
|
||||
ScaleEffect.to(
|
||||
Vector2.all(s),
|
||||
StandardEffectController(
|
||||
duration: 1.5,
|
||||
curve: Curves.bounceInOut,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user