mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
46 lines
1.1 KiB
Dart
46 lines
1.1 KiB
Dart
import 'package:flutter/animation.dart';
|
|
import 'package:meta/meta.dart';
|
|
|
|
import './effects.dart';
|
|
|
|
class RotateEffect extends PositionComponentEffect {
|
|
double radians;
|
|
double speed;
|
|
Curve curve;
|
|
double _startAngle;
|
|
double _delta;
|
|
|
|
RotateEffect({
|
|
@required this.radians, // As many radians as you want to rotate
|
|
@required this.speed, // In radians per second
|
|
this.curve,
|
|
bool isInfinite = false,
|
|
bool isAlternating = false,
|
|
bool isRelative = false,
|
|
void Function() onComplete,
|
|
}) : super(
|
|
isInfinite,
|
|
isAlternating,
|
|
isRelative: isRelative,
|
|
onComplete: onComplete,
|
|
);
|
|
|
|
@override
|
|
void initialize(_comp) {
|
|
super.initialize(_comp);
|
|
if (!isAlternating) {
|
|
endAngle = _comp.angle + radians;
|
|
}
|
|
_startAngle = component.angle;
|
|
_delta = isRelative ? radians : radians - _startAngle;
|
|
travelTime = (_delta / speed).abs();
|
|
}
|
|
|
|
@override
|
|
void update(double dt) {
|
|
super.update(dt);
|
|
final double progress = curve?.transform(percentage) ?? 1.0;
|
|
component.angle = _startAngle + _delta * progress;
|
|
}
|
|
}
|