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

docs: Use built-in camera in example #3458

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:flame/geometry.dart';
import 'package:flame/input.dart';
import 'package:flutter/painting.dart';

class CameraComponentExample extends FlameGame with PanDetector {
class CameraComponentExample extends FlameGame<AntWorld> with PanDetector {
static const description = '''
This example shows how a camera can be dynamically added into a game using
a CameraComponent.
Expand All @@ -18,6 +18,8 @@ class CameraComponentExample extends FlameGame with PanDetector {
look at the world underneath!
''';

CameraComponentExample() : super(world: AntWorld());

late final CameraComponent magnifyingGlass;
late final Vector2 center;
static const zoom = 10.0;
Expand All @@ -28,13 +30,11 @@ class CameraComponentExample extends FlameGame with PanDetector {

@override
Future<void> onLoad() async {
final world = AntWorld();
await add(world);
final camera = CameraComponent(world: world);
await add(camera);
final offset = world.curve.boundingRect().center;
center = offset.toVector2();
camera.viewfinder.position = Vector2(center.x, center.y);
world.loaded.then((_) {
final offset = world.curve.boundingRect().center;
center = offset.toVector2();
camera.viewfinder.position = Vector2(center.x, center.y);
});

magnifyingGlass =
CameraComponent(world: world, viewport: CircularViewport(radius));
Expand Down
Loading