Skip to content

Commit

Permalink
docs: Added rotate effect example and fixed multi-line (flame-engine#…
Browse files Browse the repository at this point in the history
…2024)

Added rotate effect and tested working. Effect resets.
  • Loading branch information
munsterlander authored Oct 6, 2022
1 parent ccba5a1 commit 7b47ce1
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
26 changes: 24 additions & 2 deletions doc/flame/effects.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,19 @@ Rotates the target clockwise by the specified angle relative to its current orie
is in radians. For example, the following effect will rotate the target 90º (=[tau]/4 in radians)
clockwise:

```{flutter-app}
:sources: ../flame/examples
:page: rotate_by_effect
:show: widget code infobox
:width: 180
:height: 160
```

```dart
final effect = RotateEffect.by(tau/4, EffectController(duration: 2));
final effect = RotateEffect.by(
tau/4,
EffectController(duration: 2),
);
```


Expand All @@ -163,8 +174,19 @@ final effect = RotateEffect.by(tau/4, EffectController(duration: 2));
Rotates the target clockwise to the specified angle. For example, the following will rotate the
target to look east (0º is north, 90º=[tau]/4 east, 180º=tau/2 south, and 270º=tau*3/4 west):

```{flutter-app}
:sources: ../flame/examples
:page: rotate_to_effect
:show: widget code infobox
:width: 180
:height: 160
```

```dart
final effect = RotateEffect.to(tau/4, EffectController(duration: 2));
final effect = RotateEffect.to(
tau/4,
EffectController(duration: 2),
);
```


Expand Down
4 changes: 4 additions & 0 deletions doc/flame/examples/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'package:doc_flame_examples/decorator_rotate3d.dart';
import 'package:doc_flame_examples/decorator_shadow3d.dart';
import 'package:doc_flame_examples/decorator_tint.dart';
import 'package:doc_flame_examples/drag_events.dart';
import 'package:doc_flame_examples/rotate_by_effect.dart';
import 'package:doc_flame_examples/rotate_to_effect.dart';
import 'package:doc_flame_examples/router.dart';
import 'package:doc_flame_examples/scale_by_effect.dart';
import 'package:doc_flame_examples/scale_to_effect.dart';
Expand All @@ -33,6 +35,8 @@ void main() {
'decorator_shadow3d': DecoratorShadowGame.new,
'decorator_tint': DecoratorTintGame.new,
'drag_events': DragEventsGame.new,
'rotate_by_effect': RotateByEffectGame.new,
'rotate_to_effect': RotateToEffectGame.new,
'router': RouterGame.new,
'scale_by_effect': ScaleByEffectGame.new,
'scale_to_effect': ScaleToEffectGame.new,
Expand Down
33 changes: 33 additions & 0 deletions doc/flame/examples/lib/rotate_by_effect.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:doc_flame_examples/flower.dart';
import 'package:flame/effects.dart';
import 'package:flame/experimental.dart';
import 'package:flame/game.dart';

class RotateByEffectGame extends FlameGame with HasTappableComponents {
bool reset = false;
@override
Future<void> onLoad() async {
final flower = Flower(
size: 60,
position: canvasSize / 2,
onTap: (flower) {
if (reset = !reset) {
flower.add(
RotateEffect.by(
tau / 4,
EffectController(duration: 2),
),
);
} else {
flower.add(
RotateEffect.by(
-tau / 4,
EffectController(duration: 2),
),
);
}
},
);
add(flower);
}
}
33 changes: 33 additions & 0 deletions doc/flame/examples/lib/rotate_to_effect.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:doc_flame_examples/flower.dart';
import 'package:flame/effects.dart';
import 'package:flame/experimental.dart';
import 'package:flame/game.dart';

class RotateToEffectGame extends FlameGame with HasTappableComponents {
bool reset = false;
@override
Future<void> onLoad() async {
final flower = Flower(
size: 60,
position: canvasSize / 2,
onTap: (flower) {
if (reset = !reset) {
flower.add(
RotateEffect.to(
tau / 4,
EffectController(duration: 2),
),
);
} else {
flower.add(
RotateEffect.to(
-tau / 4,
EffectController(duration: 2),
),
);
}
},
);
add(flower);
}
}

0 comments on commit 7b47ce1

Please sign in to comment.