mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 20:13:50 +08:00
Rename properties and clarify in example
This commit is contained in:
@ -46,10 +46,12 @@ square.addEffect(ScaleEffect(
|
||||
));
|
||||
```
|
||||
|
||||
## RotationalEffect
|
||||
## RotateEffect
|
||||
|
||||
Applied to `PositionComponent`s, this effect can be used to rotate the component, using an [animation curve](https://api.flutter.dev/flutter/animation/Curves-class.html).
|
||||
|
||||
The angle (`radians`) is in radians and the speed is in radians per second, so if you for example want to turn 180° in 2 seconds you set `radians: pi` and `speed: 0.25`.
|
||||
|
||||
Usage example:
|
||||
```dart
|
||||
import 'dart:math';
|
||||
@ -57,9 +59,9 @@ import 'dart:math';
|
||||
import 'package:flame/effects/effects.dart';
|
||||
|
||||
// Square is a PositionComponent
|
||||
square.addEffect(RotationalEffect(
|
||||
rotation: 2 * pi, // In radians
|
||||
speed: 1.0,
|
||||
square.addEffect(RotateEffect(
|
||||
radians: 2 * pi, // In radians
|
||||
speed: 1.0, // Radians per second
|
||||
curve: Curves.easeInOut,
|
||||
));
|
||||
```
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import 'package:flame/effects/move_effect.dart';
|
||||
import 'package:flame/effects/scale_effect.dart';
|
||||
import 'package:flame/effects/rotational_effect.dart';
|
||||
import 'package:flame/effects/rotate_effect.dart';
|
||||
import 'package:flame/gestures.dart';
|
||||
import 'package:flame/position.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -59,9 +59,9 @@ class MyGame extends BaseGame with TapDetector {
|
||||
isAlternating: true,
|
||||
));
|
||||
|
||||
orangeSquare.addEffect(RotationalEffect(
|
||||
rotation: (dx + dy) % (2 * pi),
|
||||
speed: 1.0,
|
||||
orangeSquare.addEffect(RotateEffect(
|
||||
radians: (dx + dy) % (2 * pi),
|
||||
speed: 1.0, // Radians per second
|
||||
curve: Curves.easeInOut,
|
||||
isInfinite: true,
|
||||
isAlternating: true,
|
||||
|
||||
@ -3,8 +3,8 @@ import 'package:meta/meta.dart';
|
||||
|
||||
import './effects.dart';
|
||||
|
||||
class RotationalEffect extends PositionComponentEffect {
|
||||
double rotation;
|
||||
class RotateEffect extends PositionComponentEffect {
|
||||
double radians;
|
||||
double speed;
|
||||
Curve curve;
|
||||
|
||||
@ -12,9 +12,9 @@ class RotationalEffect extends PositionComponentEffect {
|
||||
double _peakAngle;
|
||||
double _direction;
|
||||
|
||||
RotationalEffect({
|
||||
@required this.rotation,
|
||||
@required this.speed,
|
||||
RotateEffect({
|
||||
@required this.radians, // The angle to rotate to
|
||||
@required this.speed, // In radians per second
|
||||
this.curve,
|
||||
isInfinite = false,
|
||||
isAlternating = false,
|
||||
@ -24,7 +24,7 @@ class RotationalEffect extends PositionComponentEffect {
|
||||
set component(_comp) {
|
||||
super.component = _comp;
|
||||
_originalAngle = component.angle;
|
||||
_peakAngle = _originalAngle + rotation;
|
||||
_peakAngle = _originalAngle + radians;
|
||||
_direction = _peakAngle.sign;
|
||||
travelTime = (_peakAngle / speed).abs();
|
||||
}
|
||||
Reference in New Issue
Block a user