mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-04 04:47:13 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			39 lines
		
	
	
		
			939 B
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			939 B
		
	
	
	
		
			Dart
		
	
	
	
	
	
import 'package:flutter/animation.dart';
 | 
						|
import 'package:meta/meta.dart';
 | 
						|
 | 
						|
import './effects.dart';
 | 
						|
 | 
						|
class RotateEffect extends PositionComponentEffect {
 | 
						|
  double radians;
 | 
						|
  double speed;
 | 
						|
  Curve curve;
 | 
						|
 | 
						|
  double _originalAngle;
 | 
						|
  double _peakAngle;
 | 
						|
  double _direction;
 | 
						|
 | 
						|
  RotateEffect({
 | 
						|
    @required this.radians, // As many radians as you want to rotate
 | 
						|
    @required this.speed, // In radians per second
 | 
						|
    this.curve,
 | 
						|
    isInfinite = false,
 | 
						|
    isAlternating = false,
 | 
						|
  }) : super(isInfinite, isAlternating);
 | 
						|
 | 
						|
  @override
 | 
						|
  set component(_comp) {
 | 
						|
    super.component = _comp;
 | 
						|
    _originalAngle = component.angle;
 | 
						|
    _peakAngle = _originalAngle + radians;
 | 
						|
    _direction = _peakAngle.sign;
 | 
						|
    travelTime = (radians / speed).abs();
 | 
						|
  }
 | 
						|
 | 
						|
  @override
 | 
						|
  void update(double dt) {
 | 
						|
    super.update(dt);
 | 
						|
    final double c = curve?.transform(percentage) ?? 1.0;
 | 
						|
    component.angle = _originalAngle + _peakAngle * c * _direction;
 | 
						|
  }
 | 
						|
}
 |