mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 03:15:43 +08:00
OpacityEffect in the new effects engine (#1133)
* OpacityEffect example * Add OpacityEffect example * Added test for OpacityEffect * Added changelog entry * Fix dartdocs * Reset rounding errors between runs * Fix test and rounding error * Update rounding error calculation * Rounding error should be private * Bump test epsilon
This commit is contained in:
@ -1,12 +1,15 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame/effects.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flame/input.dart';
|
||||
import 'package:flame/src/effects2/opacity_effect.dart'; // ignore: implementation_imports
|
||||
import 'package:flame/src/effects2/standard_effect_controller.dart'; // ignore: implementation_imports
|
||||
|
||||
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 right flame will constantly pulse in and out of opacity and the left
|
||||
The left Ember will constantly pulse in and out of opacity and the right
|
||||
flame will change opacity when you click the screen.
|
||||
''';
|
||||
|
||||
@ -19,22 +22,22 @@ class OpacityEffectExample extends FlameGame with TapDetector {
|
||||
add(
|
||||
sprite = SpriteComponent(
|
||||
sprite: flameSprite,
|
||||
position: Vector2.all(100),
|
||||
position: Vector2(300, 100),
|
||||
size: Vector2(149, 211),
|
||||
),
|
||||
);
|
||||
|
||||
add(
|
||||
SpriteComponent(
|
||||
sprite: flameSprite,
|
||||
position: Vector2(300, 100),
|
||||
size: Vector2(149, 211),
|
||||
Ember(
|
||||
position: Vector2(180, 230),
|
||||
size: Vector2.all(100),
|
||||
)..add(
|
||||
OpacityEffect(
|
||||
opacity: 0,
|
||||
duration: 1.5,
|
||||
isInfinite: true,
|
||||
isAlternating: true,
|
||||
OpacityEffect.fadeOut(
|
||||
StandardEffectController(
|
||||
duration: 1.5,
|
||||
reverseDuration: 1.5,
|
||||
infinite: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -43,10 +46,10 @@ class OpacityEffectExample extends FlameGame with TapDetector {
|
||||
@override
|
||||
void onTap() {
|
||||
final opacity = sprite.paint.color.opacity;
|
||||
if (opacity == 1) {
|
||||
sprite.add(OpacityEffect.fadeOut());
|
||||
} else if (opacity == 0) {
|
||||
sprite.add(OpacityEffect.fadeIn());
|
||||
if (opacity >= 0.5) {
|
||||
sprite.add(OpacityEffect.fadeOut(StandardEffectController(duration: 1)));
|
||||
} else {
|
||||
sprite.add(OpacityEffect.fadeIn(StandardEffectController(duration: 1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user