mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
add sprites example
This commit is contained in:
36
doc/examples/sprites/lib/main.dart
Normal file
36
doc/examples/sprites/lib/main.dart
Normal file
@ -0,0 +1,36 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flame/flame.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flame/components/component.dart';
|
||||
import 'package:flame/game.dart';
|
||||
|
||||
void main() async {
|
||||
final Size size = await Flame.util.initialDimensions();
|
||||
final game = MyGame(size);
|
||||
runApp(game.widget);
|
||||
}
|
||||
|
||||
class MyGame extends BaseGame {
|
||||
MyGame(Size screenSize) {
|
||||
size = screenSize;
|
||||
}
|
||||
|
||||
@override
|
||||
void onAttach() {
|
||||
super.onAttach();
|
||||
|
||||
initSprites();
|
||||
}
|
||||
|
||||
void initSprites() async {
|
||||
final r = Random();
|
||||
List.generate(500, (i) => SpriteComponent.square(32, 'test.png'))
|
||||
.forEach((sprite) {
|
||||
sprite.x = r.nextInt(size.width.toInt()).toDouble();
|
||||
sprite.y = r.nextInt(size.height.toInt()).toDouble();
|
||||
add(sprite);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user