Files
flame/lib/particles/moving_particle.dart
Ivan Cherepanov 0f98a8542d chore: format
fix: doc/example/particles/readme, attempt to embed webm preview
fix: doc/example/particles better sample for chaining
refactor: Particle, dropped duration support
2019-11-28 23:02:28 +03:00

39 lines
933 B
Dart

import 'dart:ui';
import 'package:flutter/animation.dart';
import 'package:flutter/foundation.dart';
import '../particle.dart';
import '../components/mixins/single_child_particle.dart';
import '../particles/curved_particle.dart';
/// Statically offset given child [Particle] by given [Offset]
/// If you're loking to move the child, consider [MovingParticle]
class MovingParticle extends CurvedParticle with SingleChildParticle {
@override
Particle child;
final Offset from;
final Offset to;
MovingParticle({
@required this.child,
@required this.to,
this.from = Offset.zero,
double lifespan,
Curve curve = Curves.linear,
}) : super(
lifespan: lifespan,
curve: curve,
);
@override
void render(Canvas c) {
c.save();
final Offset current = Offset.lerp(from, to, progress);
c.translate(current.dx, current.dy);
super.render(c);
c.restore();
}
}