mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-01 01:18:38 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			56 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'package:flutter/animation.dart';
 | |
| import 'package:meta/meta.dart';
 | |
| 
 | |
| import '../extensions/vector2.dart';
 | |
| import 'effects.dart';
 | |
| 
 | |
| class ScaleEffect extends SimplePositionComponentEffect {
 | |
|   Vector2 size;
 | |
|   Vector2 _startSize;
 | |
|   Vector2 _delta;
 | |
| 
 | |
|   ScaleEffect({
 | |
|     @required this.size,
 | |
|     double duration, // How long it should take for completion
 | |
|     double speed, // The speed of the scaling in pixels per second
 | |
|     Curve curve,
 | |
|     bool isInfinite = false,
 | |
|     bool isAlternating = false,
 | |
|     bool isRelative = false,
 | |
|     void Function() onComplete,
 | |
|   })  : assert(
 | |
|           duration != null || speed != null,
 | |
|           "Either speed or duration necessary",
 | |
|         ),
 | |
|         super(
 | |
|           isInfinite,
 | |
|           isAlternating,
 | |
|           duration: duration,
 | |
|           speed: speed,
 | |
|           curve: curve,
 | |
|           isRelative: isRelative,
 | |
|           onComplete: onComplete,
 | |
|         );
 | |
| 
 | |
|   @override
 | |
|   void initialize(_comp) {
 | |
|     super.initialize(_comp);
 | |
|     _startSize = component.size;
 | |
|     _delta = isRelative ? size : size - _startSize;
 | |
|     if (!isAlternating) {
 | |
|       endSize = _startSize + _delta;
 | |
|     }
 | |
|     speed ??= _delta.length / duration;
 | |
|     duration ??= _delta.length / speed;
 | |
|     peakTime = isAlternating ? duration / 2 : duration;
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   void update(double dt) {
 | |
|     super.update(dt);
 | |
|     if (!hasFinished()) {
 | |
|       component.size = _startSize + _delta * curveProgress;
 | |
|     }
 | |
|   }
 | |
| }
 | 
