mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 20:13:50 +08:00
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:
@ -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));
|
||||
|
||||
Reference in New Issue
Block a user