fluttercameradeprecatedshakeflame

flutter flame camera shake deprecated


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

expect


Solution

  • 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