flutterflameforge2d

How to update the gravity in flutter flame forge2d?


I want to update the gravity according to some events in the game, but I can't find a way to change it after I initialise it in the super of the class Forge2DGame.


Solution

  • You have to use setGravity to change it.

    For example:

    class MyGame extends Forge2DGame with TapDetector {
      @override
      void onTap() {
        world.setGravity(Vector2(0, 10));
      }
    }