Improve default constructor for positioned components (#667)

This commit is contained in:
pedia
2021-02-24 00:27:17 +08:00
committed by GitHub
parent ec09ce0ce6
commit 9735cf5e08
11 changed files with 95 additions and 47 deletions

View File

@@ -19,10 +19,17 @@ class MyGame extends BaseGame {
Future<void> onLoad() async {
final r = Random();
final image = await images.load('test.png');
List.generate(500, (i) => SpriteComponent.fromImage(Vector2.all(32), image))
.forEach((sprite) {
sprite.x = r.nextInt(size.x.toInt()).toDouble();
sprite.y = r.nextInt(size.y.toInt()).toDouble();
List.generate(
500,
(i) => SpriteComponent(
position: Vector2(
r.nextInt(size.x.toInt()).toDouble(),
r.nextInt(size.x.toInt()).toDouble(),
),
size: Vector2.all(32),
sprite: Sprite(image),
),
).forEach((sprite) {
add(sprite);
});
}