Null-safety (#685)

This commit is contained in:
Luan Nico
2021-03-09 17:45:55 -05:00
committed by GitHub
parent 0855d4e3a5
commit edc54fdc34
121 changed files with 625 additions and 669 deletions

View File

@@ -19,7 +19,8 @@ class MySpriteBatchComponent extends SpriteBatchComponent
with HasGameRef<MyGame> {
@override
Future<void> onLoad() async {
spriteBatch = await gameRef.loadSpriteBatch('boom3.png');
final spriteBatch = await gameRef!.loadSpriteBatch('boom3.png');
this.spriteBatch = spriteBatch;
spriteBatch.add(
source: const Rect.fromLTWH(128 * 4.0, 128 * 4.0, 64, 128),
@@ -37,12 +38,12 @@ class MySpriteBatchComponent extends SpriteBatchComponent
const num = 100;
final r = Random();
final size = gameRef!.size;
for (var i = 0; i < num; ++i) {
final sx = r.nextInt(8) * 128.0;
final sy = r.nextInt(8) * 128.0;
final x = r.nextInt(gameRef.size.x.toInt()).toDouble();
final y =
r.nextInt(gameRef.size.y ~/ 2).toDouble() + gameRef.size.y / 2.0;
final x = r.nextInt(size.x.toInt()).toDouble();
final y = r.nextInt(size.y ~/ 2).toDouble() + size.y / 2.0;
spriteBatch.add(
source: Rect.fromLTWH(sx, sy, 128, 128),
offset: Vector2(x - 64, y - 64),
@@ -52,7 +53,7 @@ class MySpriteBatchComponent extends SpriteBatchComponent
}
class MyGame extends BaseGame {
SpriteBatch spriteBatch;
late SpriteBatch spriteBatch;
@override
Future<void> onLoad() async {