2

enter image description here

When I tried to repeat some lecture of flutter flame, most of youtube instructors teach me this way to shake screen. But IDE complaint using camera property directly was deprecated.

So, What is best way to shake camera (or viewport or world) now days?

try

  • camera.shake(); // deprecated
  • gameRef.camera.shake(); // deprecated
  • gameRef.world.shake(); // method not exists
  • gameRef.cameraComponent.shake(); // method not exists
  • gameRef.cameraComponent.viewport.shake(); // method not exists
  • gameRef.cameraComponent.camera.shake(); // method not exists

expect

  • no deprecated
김종현
  • 33
  • 1
  • 3
  • Have you read the documentation that explains what to do instead? https://pub.dev/documentation/flame/latest/game/FlameGame/camera.html – Sami Kuhmonen Jul 16 '23 at 13:57
  • @SamiKuhmonen Yes, manual said, do not use flameGame.camera directly, make cameraComponent and use that, so I did. But cameraComponent doesn't have shake method. – 김종현 Jul 16 '23 at 14:09

1 Answers1

3

The shaking of the camera has become an effect instead of a method directly on the camera, this is how you can use it with the CameraComponent:

        cameraComponent.viewfinder.add(
          MoveEffect.by(
            Vector2(5, 5),
            PerlinNoiseEffectController(duration: 0.2, frequency: 400),
          ),
        );

And of course change the parameters to your liking.

Remember to import flame_noise, since that EffectController resides in there: https://pub.dev/packages/flame_noise

spydon
  • 9,372
  • 6
  • 33
  • 63