mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-01 01:18:38 +08:00 
			
		
		
		
	feat!: Add CameraComponent to FlameGame (#2740)
This PR adds the `CameraComponent` and a `World` by default to the FlameGame.
This commit is contained in:
		| @ -22,19 +22,19 @@ class MoveEffectExample extends FlameGame { | ||||
|     an arbitrary path using `MoveEffect.along`. | ||||
|   '''; | ||||
|  | ||||
|   final world = World(); | ||||
|   late final CameraComponent cameraComponent; | ||||
|   MoveEffectExample() | ||||
|       : super( | ||||
|           camera: CameraComponent.withFixedResolution( | ||||
|             width: 400, | ||||
|             height: 600, | ||||
|           )..viewfinder.anchor = Anchor.topLeft, | ||||
|           world: _MoveEffectWorld(), | ||||
|         ); | ||||
| } | ||||
|  | ||||
| class _MoveEffectWorld extends World { | ||||
|   @override | ||||
|   void onLoad() { | ||||
|     cameraComponent = CameraComponent.withFixedResolution( | ||||
|       world: world, | ||||
|       width: 400, | ||||
|       height: 600, | ||||
|     ); | ||||
|     cameraComponent.viewfinder.anchor = Anchor.topLeft; | ||||
|     addAll([world, cameraComponent]); | ||||
|  | ||||
|     final paint1 = Paint() | ||||
|       ..style = PaintingStyle.stroke | ||||
|       ..strokeWidth = 5.0 | ||||
| @ -46,7 +46,7 @@ class MoveEffectExample extends FlameGame { | ||||
|     final paint3 = Paint()..color = const Color(0xffb372dc); | ||||
|  | ||||
|     // Red square, moving back and forth | ||||
|     world.add( | ||||
|     add( | ||||
|       RectangleComponent.square( | ||||
|         position: Vector2(20, 50), | ||||
|         size: 20, | ||||
| @ -65,7 +65,7 @@ class MoveEffectExample extends FlameGame { | ||||
|     ); | ||||
|  | ||||
|     // Green square, moving and jumping | ||||
|     world.add( | ||||
|     add( | ||||
|       RectangleComponent.square( | ||||
|         position: Vector2(20, 150), | ||||
|         size: 20, | ||||
| @ -97,7 +97,7 @@ class MoveEffectExample extends FlameGame { | ||||
|     ); | ||||
|  | ||||
|     // Purple square, vibrating from two noise controllers. | ||||
|     world.add( | ||||
|     add( | ||||
|       RectangleComponent.square( | ||||
|         size: 15, | ||||
|         position: Vector2(40, 240), | ||||
| @ -123,7 +123,7 @@ class MoveEffectExample extends FlameGame { | ||||
|     // A circle of moving rectangles. | ||||
|     final path2 = Path()..addOval(const Rect.fromLTRB(80, 230, 320, 470)); | ||||
|     for (var i = 0; i < 20; i++) { | ||||
|       world.add( | ||||
|       add( | ||||
|         RectangleComponent.square(size: 10) | ||||
|           ..position = Vector2(i * 10, 0) | ||||
|           ..paint = (Paint()..color = Colors.tealAccent) | ||||
| @ -150,7 +150,7 @@ class MoveEffectExample extends FlameGame { | ||||
|       path1.lineTo(x, y); | ||||
|     } | ||||
|     for (var i = 0; i < 40; i++) { | ||||
|       world.add( | ||||
|       add( | ||||
|         CircleComponent(radius: 5) | ||||
|           ..position = Vector2(i * 10, 0) | ||||
|           ..add( | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Lukas Klingsbo
					Lukas Klingsbo