mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-04 04:47:13 +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:flame/input.dart';
 | 
				
			||||||
import 'package:flutter/painting.dart';
 | 
					import 'package:flutter/painting.dart';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CameraComponentExample extends FlameGame with PanDetector {
 | 
					class CameraComponentExample extends FlameGame<AntWorld> with PanDetector {
 | 
				
			||||||
  static const description = '''
 | 
					  static const description = '''
 | 
				
			||||||
    This example shows how a camera can be dynamically added into a game using
 | 
					    This example shows how a camera can be dynamically added into a game using
 | 
				
			||||||
    a CameraComponent.
 | 
					    a CameraComponent.
 | 
				
			||||||
@ -18,6 +18,8 @@ class CameraComponentExample extends FlameGame with PanDetector {
 | 
				
			|||||||
    look at the world underneath! 
 | 
					    look at the world underneath! 
 | 
				
			||||||
  ''';
 | 
					  ''';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  CameraComponentExample() : super(world: AntWorld());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  late final CameraComponent magnifyingGlass;
 | 
					  late final CameraComponent magnifyingGlass;
 | 
				
			||||||
  late final Vector2 center;
 | 
					  late final Vector2 center;
 | 
				
			||||||
  static const zoom = 10.0;
 | 
					  static const zoom = 10.0;
 | 
				
			||||||
@ -28,13 +30,11 @@ class CameraComponentExample extends FlameGame with PanDetector {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  @override
 | 
					  @override
 | 
				
			||||||
  Future<void> onLoad() async {
 | 
					  Future<void> onLoad() async {
 | 
				
			||||||
    final world = AntWorld();
 | 
					    world.loaded.then((_) {
 | 
				
			||||||
    await add(world);
 | 
					      final offset = world.curve.boundingRect().center;
 | 
				
			||||||
    final camera = CameraComponent(world: world);
 | 
					      center = offset.toVector2();
 | 
				
			||||||
    await add(camera);
 | 
					      camera.viewfinder.position = Vector2(center.x, center.y);
 | 
				
			||||||
    final offset = world.curve.boundingRect().center;
 | 
					    });
 | 
				
			||||||
    center = offset.toVector2();
 | 
					 | 
				
			||||||
    camera.viewfinder.position = Vector2(center.x, center.y);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    magnifyingGlass =
 | 
					    magnifyingGlass =
 | 
				
			||||||
        CameraComponent(world: world, viewport: CircularViewport(radius));
 | 
					        CameraComponent(world: world, viewport: CircularViewport(radius));
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user