mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-09 16:17:00 +08:00
53 lines
1.2 KiB
Dart
53 lines
1.2 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../components/component.dart';
|
|
import '../components/position_component.dart';
|
|
import '../extensions/vector2.dart';
|
|
import 'effects.dart';
|
|
|
|
export './move_effect.dart';
|
|
export './rotate_effect.dart';
|
|
export './scale_effect.dart';
|
|
export './sequence_effect.dart';
|
|
|
|
class EffectHandler {
|
|
/// The effects that should run on the component
|
|
final List<ComponentEffect> _effects = [];
|
|
|
|
EffectHandler();
|
|
|
|
void update(double dt) {
|
|
_effects.removeWhere((e) => e.hasCompleted());
|
|
_effects.where((e) => !e.isPaused).forEach((e) {
|
|
if (!e.isPaused) {
|
|
e.update(dt);
|
|
}
|
|
if (e.hasCompleted()) {
|
|
e.onComplete?.call();
|
|
}
|
|
});
|
|
}
|
|
|
|
/// Add an effect to the handler
|
|
void add(ComponentEffect effect, Component component) {
|
|
_effects.add(effect..initialize(component));
|
|
}
|
|
|
|
/// Mark an effect for removal
|
|
void removeEffect(ComponentEffect effect) {
|
|
effect.dispose();
|
|
}
|
|
|
|
/// Remove all effects
|
|
void clearEffects() {
|
|
_effects.forEach(removeEffect);
|
|
}
|
|
|
|
/// Get a list of non removed effects
|
|
List<ComponentEffect> get effects {
|
|
return List<ComponentEffect>.from(_effects)
|
|
..where((e) => !e.hasCompleted());
|
|
}
|
|
}
|