mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-04 04:47:13 +08:00 
			
		
		
		
	fix: doc/example/particles/readme, attempt to embed webm preview fix: doc/example/particles better sample for chaining refactor: Particle, dropped duration support
		
			
				
	
	
		
			39 lines
		
	
	
		
			933 B
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			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();
 | 
						|
  }
 | 
						|
}
 |