mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-13 03:10:42 +08:00
Null-safety (#685)
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user