Created
June 13, 2022 01:15
-
-
Save eseidel/c85153145005a4706c439fa902b6bc8d to your computer and use it in GitHub Desktop.
confused by center behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flame/components.dart'; | |
import 'package:flame/game.dart'; | |
import 'package:flutter/material.dart'; | |
class FooGame extends FlameGame { | |
@override | |
Future<void> onLoad() async { | |
debugMode = true; | |
var paint = Paint()..color = Colors.green; | |
double rectSize = 50; | |
var rect1 = RectangleComponent.square( | |
size: rectSize, | |
paint: paint, | |
anchor: Anchor.center, | |
); | |
var rect2 = RectangleComponent.square( | |
size: rectSize, | |
paint: paint, | |
anchor: Anchor.center, | |
); | |
var rect3 = RectangleComponent.square( | |
size: rectSize, | |
paint: paint, | |
anchor: Anchor.center, | |
); | |
rect2.add(rect3); | |
rect1.add(rect2); | |
add(rect1); | |
print("rect1.position: ${rect1.position}"); | |
print("rect2.position: ${rect2.position}"); | |
print("rect3.position: ${rect3.position}"); | |
double worldSize = 1500; | |
var worldBounds = Rect.fromLTWH(-worldSize, -worldSize, 2 * worldSize, 2 * worldSize); | |
camera.followComponent(rect1, worldBounds: worldBounds); | |
} | |
} | |
class MyGame extends StatelessWidget { | |
const MyGame({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return GameWidget(game: FooGame()); | |
} | |
} | |
void main() { | |
runApp(const MyGame()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment