feat!: Add CameraComponent to FlameGame (#2740)

This PR adds the `CameraComponent` and a `World` by default to the
FlameGame.
This commit is contained in:
Lukas Klingsbo
2023-09-18 21:06:37 +02:00
committed by GitHub
parent 5be6fc8cae
commit 7c2f400076
89 changed files with 1107 additions and 821 deletions

View File

@ -12,22 +12,23 @@ class RemoveEffectExample extends FlameGame {
disappear after a 0.5 second delay.
''';
final world = World();
late final CameraComponent cameraComponent;
RemoveEffectExample()
: super(
camera: CameraComponent.withFixedResolution(
width: 400,
height: 600,
)..viewfinder.anchor = Anchor.topLeft,
world: _RemoveEffectWorld(),
);
}
class _RemoveEffectWorld extends World {
@override
void onLoad() {
super.onMount();
cameraComponent = CameraComponent.withFixedResolution(
world: world,
width: 400,
height: 600,
);
cameraComponent.viewfinder.anchor = Anchor.topLeft;
addAll([cameraComponent, world]);
super.onLoad();
final rng = Random();
for (var i = 0; i < 20; i++) {
world.add(_RandomCircle.random(rng));
add(_RandomCircle.random(rng));
}
}
}