mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-03 20:36:31 +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).
|
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:
|
Usage example:
|
||||||
```dart
|
```dart
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
@ -57,9 +59,9 @@ import 'dart:math';
|
|||||||
import 'package:flame/effects/effects.dart';
|
import 'package:flame/effects/effects.dart';
|
||||||
|
|
||||||
// Square is a PositionComponent
|
// Square is a PositionComponent
|
||||||
square.addEffect(RotationalEffect(
|
square.addEffect(RotateEffect(
|
||||||
rotation: 2 * pi, // In radians
|
radians: 2 * pi, // In radians
|
||||||
speed: 1.0,
|
speed: 1.0, // Radians per second
|
||||||
curve: Curves.easeInOut,
|
curve: Curves.easeInOut,
|
||||||
));
|
));
|
||||||
```
|
```
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import 'package:flame/effects/move_effect.dart';
|
import 'package:flame/effects/move_effect.dart';
|
||||||
import 'package:flame/effects/scale_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/gestures.dart';
|
||||||
import 'package:flame/position.dart';
|
import 'package:flame/position.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -59,9 +59,9 @@ class MyGame extends BaseGame with TapDetector {
|
|||||||
isAlternating: true,
|
isAlternating: true,
|
||||||
));
|
));
|
||||||
|
|
||||||
orangeSquare.addEffect(RotationalEffect(
|
orangeSquare.addEffect(RotateEffect(
|
||||||
rotation: (dx + dy) % (2 * pi),
|
radians: (dx + dy) % (2 * pi),
|
||||||
speed: 1.0,
|
speed: 1.0, // Radians per second
|
||||||
curve: Curves.easeInOut,
|
curve: Curves.easeInOut,
|
||||||
isInfinite: true,
|
isInfinite: true,
|
||||||
isAlternating: true,
|
isAlternating: true,
|
||||||
|
|||||||
@ -3,8 +3,8 @@ import 'package:meta/meta.dart';
|
|||||||
|
|
||||||
import './effects.dart';
|
import './effects.dart';
|
||||||
|
|
||||||
class RotationalEffect extends PositionComponentEffect {
|
class RotateEffect extends PositionComponentEffect {
|
||||||
double rotation;
|
double radians;
|
||||||
double speed;
|
double speed;
|
||||||
Curve curve;
|
Curve curve;
|
||||||
|
|
||||||
@ -12,9 +12,9 @@ class RotationalEffect extends PositionComponentEffect {
|
|||||||
double _peakAngle;
|
double _peakAngle;
|
||||||
double _direction;
|
double _direction;
|
||||||
|
|
||||||
RotationalEffect({
|
RotateEffect({
|
||||||
@required this.rotation,
|
@required this.radians, // The angle to rotate to
|
||||||
@required this.speed,
|
@required this.speed, // In radians per second
|
||||||
this.curve,
|
this.curve,
|
||||||
isInfinite = false,
|
isInfinite = false,
|
||||||
isAlternating = false,
|
isAlternating = false,
|
||||||
@ -24,7 +24,7 @@ class RotationalEffect extends PositionComponentEffect {
|
|||||||
set component(_comp) {
|
set component(_comp) {
|
||||||
super.component = _comp;
|
super.component = _comp;
|
||||||
_originalAngle = component.angle;
|
_originalAngle = component.angle;
|
||||||
_peakAngle = _originalAngle + rotation;
|
_peakAngle = _originalAngle + radians;
|
||||||
_direction = _peakAngle.sign;
|
_direction = _peakAngle.sign;
|
||||||
travelTime = (_peakAngle / speed).abs();
|
travelTime = (_peakAngle / speed).abs();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user