mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
47 lines
1.0 KiB
Dart
47 lines
1.0 KiB
Dart
import 'package:flutter/animation.dart';
|
|
import 'package:meta/meta.dart';
|
|
|
|
import '../extensions/vector2.dart';
|
|
import 'effects.dart';
|
|
|
|
class ScaleEffect extends PositionComponentEffect {
|
|
Vector2 size;
|
|
double speed;
|
|
Curve curve;
|
|
Vector2 _startSize;
|
|
Vector2 _delta;
|
|
|
|
ScaleEffect({
|
|
@required this.size,
|
|
@required this.speed,
|
|
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) {
|
|
endSize = size.clone();
|
|
}
|
|
_startSize = component.size;
|
|
_delta = isRelative ? size : size - _startSize;
|
|
travelTime = _delta.length / speed;
|
|
}
|
|
|
|
@override
|
|
void update(double dt) {
|
|
super.update(dt);
|
|
final double progress = curve?.transform(percentage) ?? 1.0;
|
|
component.size = _startSize + _delta * progress;
|
|
}
|
|
}
|