Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Add CameraComponent to FlameGame #2740

Merged
merged 27 commits into from
Sep 18, 2023
Merged

feat!: Add CameraComponent to FlameGame #2740

merged 27 commits into from
Sep 18, 2023

Conversation

spydon
Copy link
Member

@spydon spydon commented Sep 15, 2023

Description

This PR adds the CameraComponent and a World by default to the FlameGame.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.

Migration instructions

We'll treat this as a breaking change since the cameraComponent name will clash with many of our users implementations, luckily it is very easy to migrate.

If you have a game like this currently:

class MyGame extends FlameGame {
  late final CameraComponent cameraComponent;
  late final World world;

  Future<void> onLoad() async {
    world = World()
    cameraComponent = CameraComponent(world: world);
    add(world);
    add(cameraComponent);
    world.add(MyComponent());
  }
}

then you simply have to remove your own references to cameraComponent and world, so that it becomes like this:

class MyGame extends FlameGame {
  Future<void> onLoad() async {
    world.add(MyComponent());
  }
}

If you are using CameraComponent.withFixedResolution you can migrate to this:

class MyGame extends FlameGame {
  MyGame() : super(
    cameraComponent: CameraComponent.withFixedResolution(
      width: 800,
      height: 600,
    ),
  );

  Future<void> onLoad() async {
    world.add(MyComponent());
  }
}

packages/flame/lib/src/game/flame_game.dart Outdated Show resolved Hide resolved
doc/flame/game.md Show resolved Hide resolved
@spydon spydon merged commit 7c2f400 into main Sep 18, 2023
7 checks passed
@spydon spydon deleted the spydon/camera-component branch September 18, 2023 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants