-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement Fade class and transition effect to level transitions
- Loading branch information
1 parent
faa0f74
commit fff9933
Showing
3 changed files
with
93 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'package:flame/components.dart'; | ||
import 'package:flame/effects.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class FadeEffect extends RectangleComponent { | ||
OpacityEffect? fadeEffect; | ||
|
||
FadeEffect(Vector2 screenSize) | ||
: super( | ||
size: screenSize, | ||
anchor: Anchor.topLeft, | ||
paint: Paint() | ||
..color = Colors.black.withOpacity(0), // Start transparent | ||
priority: | ||
100, // High priority to ensure it renders above other components | ||
); | ||
|
||
void startFade() { | ||
// If a fade effect is already active, remove it | ||
if (fadeEffect != null) { | ||
fadeEffect?.removeFromParent(); | ||
} | ||
|
||
// Create a new fade-in effect | ||
fadeEffect = OpacityEffect.to( | ||
1.0, // Target opacity (fully opaque) | ||
EffectController(duration: 1.0), // Duration in seconds | ||
onComplete: () { | ||
// Clear the effect after it completes | ||
fadeEffect = null; | ||
}, | ||
); | ||
|
||
// Add the new effect to the component | ||
add(fadeEffect!); | ||
} | ||
} |
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