Search code examples
flame

why camera from my doc is different to the example


I followed a tutorial and code looks like this:

class MyGame extends Forge2DGame{
  @override
  Future<void> onLoad() async {
    camera.toString(); // <= this camera is a Vector2
  }
}

But what I learned from another tutorial is like this:

class SpacescapeGame extends FlameGame{
  @override
  Future<void> onLoad() async {
    camera.shake(); // <= this camera is a Camera class
  }
}

What I understand is Forge2DGame extends BaseGame, BaseGame extends FlameGame https://pub.dev/documentation/bonfire/latest/base_base_game/BaseGame-class.html

but why I cant use camera.shake as second tutorial showed? thank you for your explanation!


Solution

  • I recommend that you read the Flame documentation instead of the bonfire documentation if you want to write a Flame game that is not involving bonfire.

    The camera for Forge2DGame is the same camera as is used for FlameGame, you have most likely added some other variable that is also called camera which is shadowing the real camera.

    Also make sure that you are on the latest version of flame (1.4.0) and the latest version of flame_forge2d (0.12.3).