flutter flame camera shake deprecated

378 Views Asked by At

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
1

There are 1 best solutions below

1
spydon On BEST ANSWER

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