mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 11:43:19 +08:00
add sprites example
This commit is contained in:
76
doc/examples/sprites/.gitignore
vendored
Normal file
76
doc/examples/sprites/.gitignore
vendored
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
# Miscellaneous
|
||||||
|
*.class
|
||||||
|
*.log
|
||||||
|
*.pyc
|
||||||
|
*.swp
|
||||||
|
.DS_Store
|
||||||
|
.atom/
|
||||||
|
.buildlog/
|
||||||
|
.history
|
||||||
|
.svn/
|
||||||
|
|
||||||
|
# IntelliJ related
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Visual Studio Code related
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
# Flutter/Dart/Pub related
|
||||||
|
**/doc/api/
|
||||||
|
.dart_tool/
|
||||||
|
.flutter-plugins
|
||||||
|
.packages
|
||||||
|
.pub-cache/
|
||||||
|
.pub/
|
||||||
|
/build/
|
||||||
|
|
||||||
|
# Android related
|
||||||
|
**/android/**/gradle-wrapper.jar
|
||||||
|
**/android/.gradle
|
||||||
|
**/android/captures/
|
||||||
|
**/android/gradlew
|
||||||
|
**/android/gradlew.bat
|
||||||
|
**/android/local.properties
|
||||||
|
**/android/**/GeneratedPluginRegistrant.java
|
||||||
|
|
||||||
|
# iOS/XCode related
|
||||||
|
**/ios/**/*.mode1v3
|
||||||
|
**/ios/**/*.mode2v3
|
||||||
|
**/ios/**/*.moved-aside
|
||||||
|
**/ios/**/*.pbxuser
|
||||||
|
**/ios/**/*.perspectivev3
|
||||||
|
**/ios/**/*sync/
|
||||||
|
**/ios/**/.sconsign.dblite
|
||||||
|
**/ios/**/.tags*
|
||||||
|
**/ios/**/.vagrant/
|
||||||
|
**/ios/**/DerivedData/
|
||||||
|
**/ios/**/Icon?
|
||||||
|
**/ios/**/Pods/
|
||||||
|
**/ios/**/.symlinks/
|
||||||
|
**/ios/**/profile
|
||||||
|
**/ios/**/xcuserdata
|
||||||
|
**/ios/.generated/
|
||||||
|
**/ios/Flutter/App.framework
|
||||||
|
**/ios/Flutter/Flutter.framework
|
||||||
|
**/ios/Flutter/Generated.xcconfig
|
||||||
|
**/ios/Flutter/app.flx
|
||||||
|
**/ios/Flutter/app.zip
|
||||||
|
**/ios/Flutter/flutter_assets/
|
||||||
|
**/ios/ServiceDefinitions.json
|
||||||
|
**/ios/Runner/GeneratedPluginRegistrant.*
|
||||||
|
|
||||||
|
# Exceptions to above rules.
|
||||||
|
!**/ios/**/default.mode1v3
|
||||||
|
!**/ios/**/default.mode2v3
|
||||||
|
!**/ios/**/default.pbxuser
|
||||||
|
!**/ios/**/default.perspectivev3
|
||||||
|
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
|
||||||
|
|
||||||
|
macos
|
||||||
|
|
||||||
|
test
|
||||||
|
|
||||||
|
.flutter-plugins-dependencies
|
||||||
10
doc/examples/sprites/.metadata
Normal file
10
doc/examples/sprites/.metadata
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# This file tracks properties of this Flutter project.
|
||||||
|
# Used by Flutter tool to assess capabilities and perform upgrades etc.
|
||||||
|
#
|
||||||
|
# This file should be version controlled and should not be manually edited.
|
||||||
|
|
||||||
|
version:
|
||||||
|
revision: 7fc14a55af64462763d28abfb4e610086c6e0f39
|
||||||
|
channel: dev
|
||||||
|
|
||||||
|
project_type: app
|
||||||
3
doc/examples/sprites/README.md
Normal file
3
doc/examples/sprites/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# sprites
|
||||||
|
|
||||||
|
A Flame game showcasing how to render 500 sprites
|
||||||
BIN
doc/examples/sprites/assets/images/test.png
Normal file
BIN
doc/examples/sprites/assets/images/test.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 253 B |
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
21
doc/examples/sprites/pubspec.yaml
Normal file
21
doc/examples/sprites/pubspec.yaml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
name: sprites
|
||||||
|
description: Flame sample game showcasing rendering 500 sprites
|
||||||
|
|
||||||
|
version: 1.0.0+1
|
||||||
|
|
||||||
|
environment:
|
||||||
|
sdk: ">=2.1.0 <3.0.0"
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
flutter:
|
||||||
|
sdk: flutter
|
||||||
|
flame:
|
||||||
|
path: ../../../
|
||||||
|
|
||||||
|
dev_dependencies:
|
||||||
|
flutter_test:
|
||||||
|
sdk: flutter
|
||||||
|
|
||||||
|
flutter:
|
||||||
|
assets:
|
||||||
|
- assets/images/test.png
|
||||||
Reference in New Issue
Block a user