feat(effects): Added SineEffectController (#1262)

An effect controller that represents a single period of the sine function. Use this to create
natural-looking harmonic oscillations. Two perpendicular move effects governed by
SineEffectControllers with different periods, will create a [Lissajous curve].
This commit is contained in:
Pasha Stetsenko
2021-12-27 15:12:39 -08:00
committed by GitHub
parent 7c6ae6def3
commit c888703d6e
5 changed files with 115 additions and 2 deletions

View File

@ -8,10 +8,15 @@ class EffectControllersExample extends FlameGame {
static const description = '''
This page demonstrates application of various non-standard effect
controllers.
The first white square has a ZigzagEffectController with period 1. The
orange square next to it has two move effects, each with a
orange square next to it has two move effects, each with a
ZigzagEffectController.
The lime square has a SineEffectController with the same period of 1s. The
violet square next to it has two move effects, each with a
SineEffectController with periods, but one of the effects is slightly
delayed.
''';
@override
@ -44,5 +49,35 @@ class EffectControllersExample extends FlameGame {
),
]),
);
add(
RectangleComponent.square(
position: Vector2(140, 50),
size: 20,
paint: Paint()..color = const Color(0xffbeff63),
)..add(
MoveEffect.by(
Vector2(0, 20),
InfiniteEffectController(SineEffectController(period: 1)),
),
),
);
add(
RectangleComponent.square(
position: Vector2(190, 50),
size: 10,
paint: Paint()..color = const Color(0xffb663ff),
)..addAll([
MoveEffect.by(
Vector2(0, 20),
InfiniteEffectController(SineEffectController(period: 1))
..advance(0.25),
),
MoveEffect.by(
Vector2(10, 0),
InfiniteEffectController(SineEffectController(period: 1)),
),
]),
);
}
}