-
-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds a new OpacityProvider interface which should be implemented by components that want to use OpacityEffect. This makes OpacityEffect decoupled from HasPaint.
- Loading branch information
1 parent
3649b9b
commit 0255cc3
Showing
10 changed files
with
387 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'package:doc_flame_examples/flower.dart'; | ||
import 'package:flame/components.dart'; | ||
import 'package:flame/effects.dart'; | ||
import 'package:flame/experimental.dart'; | ||
import 'package:flame/game.dart'; | ||
|
||
class OpacityEffectWithTargetGame extends FlameGame with HasTappableComponents { | ||
bool reset = false; | ||
|
||
// This reference needs to be stored because every new instance of | ||
// OpacityProvider caches the opacity ratios at the time on creation. | ||
late OpacityProvider _borderOpacityProvider; | ||
|
||
@override | ||
Future<void> onLoad() async { | ||
final flower = Flower( | ||
position: size / 2, | ||
size: 60, | ||
onTap: _onTap, | ||
)..anchor = Anchor.center; | ||
|
||
_borderOpacityProvider = flower.opacityProviderOfList( | ||
paintIds: const [FlowerPaint.paintId1, FlowerPaint.paintId2], | ||
); | ||
|
||
add(flower); | ||
} | ||
|
||
void _onTap(Flower flower) { | ||
if (reset = !reset) { | ||
flower.add( | ||
OpacityEffect.to( | ||
0.2, | ||
EffectController(duration: 0.75), | ||
target: _borderOpacityProvider, | ||
), | ||
); | ||
} else { | ||
flower.add( | ||
OpacityEffect.fadeIn( | ||
EffectController(duration: 0.75), | ||
target: _borderOpacityProvider, | ||
), | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,37 @@ | ||
import 'package:doc_flame_examples/ember.dart'; | ||
import 'package:doc_flame_examples/flower.dart'; | ||
import 'package:flame/components.dart'; | ||
import 'package:flame/effects.dart'; | ||
import 'package:flame/experimental.dart'; | ||
import 'package:flame/game.dart'; | ||
|
||
class OpacityToEffectGame extends FlameGame with HasTappableComponents { | ||
bool reset = false; | ||
|
||
@override | ||
Future<void> onLoad() async { | ||
final ember = EmberPlayer( | ||
final flower = Flower( | ||
position: size / 2, | ||
size: size / 4, | ||
onTap: (ember) { | ||
if (reset = !reset) { | ||
ember.add( | ||
OpacityEffect.to( | ||
0.2, | ||
EffectController(duration: 0.75), | ||
), | ||
); | ||
} else { | ||
ember.add( | ||
OpacityEffect.to( | ||
1.0, | ||
EffectController(duration: 0.75), | ||
), | ||
); | ||
} | ||
}, | ||
size: 60, | ||
onTap: _onTap, | ||
)..anchor = Anchor.center; | ||
|
||
add(ember); | ||
add(flower); | ||
} | ||
|
||
void _onTap(Flower flower) { | ||
if (reset = !reset) { | ||
flower.add( | ||
OpacityEffect.to( | ||
0.2, | ||
EffectController(duration: 0.75), | ||
), | ||
); | ||
} else { | ||
flower.add( | ||
OpacityEffect.fadeIn( | ||
EffectController(duration: 0.75), | ||
), | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.