mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 01:18:38 +08:00
* Update effectController
* move effect controllers into the controllers/ directory
* Add .forward property to EffectController
* SimpleEffectController supports reverse time
* Fixing some compile errors
* rename SimpleEffectController -> LinearEffectController
* minor cleanup
* DurationEffectController and PauseEffectController
* ReverseLinearEffectController
* CurvedEffectController and its reverse
* InfiniteEffectController
* Added EffectController.recede()
* Add EffectController.update()
* Add InfiniteEffectController'
* RepeatedEffectController
* SequenceEffectController
* DelayedEffectController
* Restore the [EffectController.started] property
* minor
* Rename reset() -> setToStart()
* time direction is now managed from the Effect class
* StandardEffectController replaced with function standardController()
* update some doc-comments
* flutter analyze
* flutter format
* fix some tests
* more test fixes
* fix remaining tests
* format
* rename local variable
* minor simplification
* Expand docs in PauseEffectController
* added tests
* Curved controller test
* fix errors
* formatting
* added more tests
* format
* fix RepeatedEffectController
* more tests
* format
* changelog
* increase tolerance
* Replaced standardController with factory EffectController constructor
* Added parameter EffectController({alternate=false})
* Added default for curve= parameter
* rename
* rename tests
* added more exports
* rename tests
* rename src/effects2
Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
54 lines
1.4 KiB
Dart
54 lines
1.4 KiB
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/effects.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame/input.dart';
|
|
import '../../commons/ember.dart';
|
|
|
|
class OpacityEffectExample extends FlameGame with TapDetector {
|
|
static const String description = '''
|
|
In this example we show how the `OpacityEffect` can be used in two ways.
|
|
The left Ember will constantly pulse in and out of opacity and the right
|
|
flame will change opacity when you click the screen.
|
|
''';
|
|
|
|
late final SpriteComponent sprite;
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
await super.onLoad();
|
|
final flameSprite = await loadSprite('flame.png');
|
|
add(
|
|
sprite = SpriteComponent(
|
|
sprite: flameSprite,
|
|
position: Vector2(300, 100),
|
|
size: Vector2(149, 211),
|
|
),
|
|
);
|
|
|
|
add(
|
|
Ember(
|
|
position: Vector2(180, 230),
|
|
size: Vector2.all(100),
|
|
)..add(
|
|
OpacityEffect.fadeOut(
|
|
EffectController(
|
|
duration: 1.5,
|
|
reverseDuration: 1.5,
|
|
infinite: true,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
void onTap() {
|
|
final opacity = sprite.paint.color.opacity;
|
|
if (opacity >= 0.5) {
|
|
sprite.add(OpacityEffect.fadeOut(EffectController(duration: 1)));
|
|
} else {
|
|
sprite.add(OpacityEffect.fadeIn(EffectController(duration: 1)));
|
|
}
|
|
}
|
|
}
|