add sprites example

This commit is contained in:
Erlend Fagerheim
2020-04-15 22:25:14 +02:00
parent 887d2303bc
commit 8b232c9e1d
6 changed files with 146 additions and 0 deletions

76
doc/examples/sprites/.gitignore vendored Normal file
View 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

View 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

View File

@ -0,0 +1,3 @@
# sprites
A Flame game showcasing how to render 500 sprites

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 B

View 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);
});
}
}

View 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