I am working on a side shooter with Flame, and would like the screen to shake when the player is hit by a bullet.
I have found this post: /a/76698880/1843141
I implemented it as follows but that’s not working:
class MyGame extends FlameGame {
@override
Future<void> onLoad() async {
await Flame.device.fullScreen();
await Flame.device.setLandscape();
...
camera = CameraComponent.withFixedResolution(
world: world,
width: 800,
height: 600,
);
add(camera);
...
}
// I call this when the player's sprite detects a collision
void shakeScreen() {
camera.viewfinder.add(
MoveEffect.by(
Vector2(30, 30),
NoiseEffectController(
duration: 0.2,
noise: PerlinNoise(frequency: 40),
),
),
);
}
...
}
When I use the same method on a sprite, it shakes ¯(ツ)/¯