mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-04 04:47:13 +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,
 | 
						|
    isInfinite = false,
 | 
						|
    isAlternating = false,
 | 
						|
    isRelative = false,
 | 
						|
    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;
 | 
						|
  }
 | 
						|
}
 |