mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 20:36:31 +08:00
fix: doc/examples/particles, added web to .gitignore feat: doc/examples/particles, added more examples, refactor: Particle does not extend Component refactor: Particle subclasses in separate folder refactor: ParticleComponent is now simple container fix: SingleChildParticle, asserts for child existing feat: AnimationParticle for Flame Animation feat: ComponentParticle for Flame Component feat: SpriteParticle for Flame Sprite
50 lines
1.0 KiB
Dart
50 lines
1.0 KiB
Dart
import 'dart:ui';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import '../animation.dart';
|
|
import '../particle.dart';
|
|
import '../position.dart';
|
|
|
|
class AnimationParticle extends Particle {
|
|
final Animation animation;
|
|
final Position size;
|
|
final Paint overridePaint;
|
|
final bool alignAnimationTime;
|
|
|
|
AnimationParticle({
|
|
@required this.animation,
|
|
this.size,
|
|
this.overridePaint,
|
|
double lifespan,
|
|
Duration duration,
|
|
this.alignAnimationTime = true,
|
|
}) : super(
|
|
lifespan: lifespan,
|
|
duration: duration,
|
|
);
|
|
|
|
@override
|
|
void setLifespan(double lifespan) {
|
|
super.setLifespan(lifespan);
|
|
|
|
if (alignAnimationTime) {
|
|
animation.stepTime = lifespan / animation.frames.length;
|
|
animation.reset();
|
|
}
|
|
}
|
|
|
|
@override
|
|
void render(Canvas canvas) {
|
|
animation.getSprite().renderCentered(canvas, Position.empty(),
|
|
overridePaint: overridePaint,
|
|
size: size
|
|
);
|
|
}
|
|
|
|
@override
|
|
void update(double dt) {
|
|
super.update(dt);
|
|
animation.update(dt);
|
|
}
|
|
} |