Anchor Effects¶
Anchor effects are used to change the anchor point of a component over time. The anchor point is the point around which the component rotates and scales.
AnchorByEffect
¶
Changes the location of the target’s anchor by the specified offset. This effect can also be created
using AnchorEffect.by()
.
anchor_by_effect.dart
1import 'package:doc_flame_examples/flower.dart';
2import 'package:flame/effects.dart';
3import 'package:flame/game.dart';
4
5class AnchorByEffectGame extends FlameGame {
6 bool reset = false;
7
8 @override
9 Future<void> onLoad() async {
10 final flower = Flower(
11 size: 60,
12 position: canvasSize / 2,
13 onTap: (flower) {
14 flower.add(
15 AnchorByEffect(
16 reset ? Vector2(-0.5, -0.5) : Vector2(0.5, 0.5),
17 EffectController(speed: 1),
18 ),
19 );
20 reset = !reset;
21 },
22 );
23 add(flower);
24 }
25}
final effect = AnchorByEffect(
Vector2(0.1, 0.1),
EffectController(speed: 1),
);
AnchorToEffect
¶
Changes the location of the target’s anchor. This effect can also be created using
AnchorEffect.to()
.
anchor_to_effect.dart
1import 'package:doc_flame_examples/flower.dart';
2import 'package:flame/components.dart';
3import 'package:flame/effects.dart';
4import 'package:flame/game.dart';
5
6class AnchorToEffectGame extends FlameGame {
7 @override
8 Future<void> onLoad() async {
9 final flower = Flower(
10 size: 60,
11 position: canvasSize / 2,
12 onTap: (flower) {
13 flower.add(
14 AnchorToEffect(
15 flower.anchor == Anchor.center ? Anchor.bottomLeft : Anchor.center,
16 EffectController(speed: 1),
17 ),
18 );
19 },
20 );
21 add(flower);
22 }
23}
final effect = AnchorToEffect(
Anchor.center,
EffectController(speed: 1),
);
The content on this page is licensed under the CC BY 4.0 License,
and code samples under the MIT License.