Files
flame/examples/lib/stories/effects/size_effect.dart
Lukas Klingsbo b7a2d3fdf8 Simplified the usage of ShapeComponent (#1068)
* Simplified the usage of ShapeComponent

* Default constructor for _RandomCircle

* Use default constructor

* Forced Anchor.center on ShapeComponent

* Fix examples using SquareComponent

* Removed unnecesary import

* Renamed edgeLength to size
2021-11-03 14:30:58 +01:00

48 lines
1.2 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';
import '../../commons/square_component.dart';
const sizeInfo = '''
The `SizeEffect` changes the size of the component, the sizes of the children
will stay the same.
In this example you can tap the screen and the component will size up or down,
depending on its current state.
''';
class SizeEffectGame extends FlameGame with TapDetector {
late SquareComponent square;
bool grow = true;
@override
Future<void> onLoad() async {
await super.onLoad();
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 ? 300.0 : 100.0;
grow = !grow;
square.add(
SizeEffect(
size: Vector2.all(s),
speed: 250.0,
curve: Curves.bounceInOut,
),
);
}
}