mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-10-31 17:06:50 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'package:flutter/animation.dart';
 | |
| import 'package:meta/meta.dart';
 | |
| 
 | |
| import 'effects.dart';
 | |
| 
 | |
| class RotateEffect extends SimplePositionComponentEffect {
 | |
|   double angle;
 | |
|   double _startAngle;
 | |
|   double _delta;
 | |
| 
 | |
|   RotateEffect({
 | |
|     @required this.angle, // As many radians as you want to rotate
 | |
|     double duration, // How long it should take for completion
 | |
|     double speed, // The speed of rotation in radians/s
 | |
|     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);
 | |
|     _startAngle = component.angle;
 | |
|     _delta = isRelative ? angle : angle - _startAngle;
 | |
|     if (!isAlternating) {
 | |
|       endAngle = _startAngle + _delta;
 | |
|     }
 | |
|     speed ??= _delta / duration;
 | |
|     duration ??= _delta / speed;
 | |
|     peakTime = isAlternating ? duration / 2 : duration;
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   void update(double dt) {
 | |
|     super.update(dt);
 | |
|     if (!hasFinished()) {
 | |
|       component.angle = _startAngle + _delta * curveProgress;
 | |
|     }
 | |
|   }
 | |
| }
 | 
