docs: Use built-in camera in example (#3458)

This uses the built-in camera in the example, so that people don't
create new default cameras accidentally.
This commit is contained in:
Lukas Klingsbo
2025-01-26 18:07:09 +01:00
committed by GitHub
parent 324ac2bfc2
commit 13bb7cf44b

View File

@ -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.
@ -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;
@ -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));