Files
flame/examples/lib/stories/effects/scale_effect_example.dart
Pasha Stetsenko bfcda073bb Effect controllers restructuring (#1134)
* Update effectController

* move effect controllers into the controllers/ directory

* Add .forward property to EffectController

* SimpleEffectController supports reverse time

* Fixing some compile errors

* rename SimpleEffectController -> LinearEffectController

* minor cleanup

* DurationEffectController and PauseEffectController

* ReverseLinearEffectController

* CurvedEffectController and its reverse

* InfiniteEffectController

* Added EffectController.recede()

* Add EffectController.update()

* Add InfiniteEffectController'

* RepeatedEffectController

* SequenceEffectController

* DelayedEffectController

* Restore the [EffectController.started] property

* minor

* Rename reset() -> setToStart()

* time direction is now managed from the Effect class

* StandardEffectController replaced with function standardController()

* update some doc-comments

* flutter analyze

* flutter format

* fix some tests

* more test fixes

* fix remaining tests

* format

* rename local variable

* minor simplification

* Expand docs in PauseEffectController

* added tests

* Curved controller test

* fix errors

* formatting

* added more tests

* format

* fix RepeatedEffectController

* more tests

* format

* changelog

* increase tolerance

* Replaced standardController with factory EffectController constructor

* Added parameter EffectController({alternate=false})

* Added default for curve= parameter

* rename

* rename tests

* added more exports

* rename tests

* rename src/effects2

Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
2021-12-04 15:58:42 +00:00

53 lines
1.3 KiB
Dart

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:flutter/material.dart';
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.
''';
late RectangleComponent square;
bool grow = true;
@override
Future<void> onLoad() async {
await super.onLoad();
square = RectangleComponent.square(
size: 100,
position: Vector2.all(200),
paint: BasicPalette.white.paint()..style = PaintingStyle.stroke,
);
final childSquare = RectangleComponent.square(
position: Vector2.all(70),
size: 20,
);
square.add(childSquare);
add(square);
}
@override
void onTap() {
final s = grow ? 3.0 : 1.0;
grow = !grow;
square.add(
ScaleEffect.to(
Vector2.all(s),
EffectController(
duration: 1.5,
curve: Curves.bounceInOut,
),
),
);
}
}