diff --git a/CHANGELOG.md b/CHANGELOG.md index efdea3ba4..e0125c4d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## [next] - Svg support +- Adding `Animation#reversed` allowing a new reversed animation to be created from an existing animation. ## [0.10.2] - Fixed some warnings and formatting diff --git a/doc/examples/animations/.gitignore b/doc/examples/animations/.gitignore new file mode 100644 index 000000000..07488ba61 --- /dev/null +++ b/doc/examples/animations/.gitignore @@ -0,0 +1,70 @@ +# 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 diff --git a/doc/examples/animations/.metadata b/doc/examples/animations/.metadata new file mode 100644 index 000000000..6a633e088 --- /dev/null +++ b/doc/examples/animations/.metadata @@ -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 diff --git a/doc/examples/animations/README.md b/doc/examples/animations/README.md new file mode 100644 index 000000000..45bf2f1f4 --- /dev/null +++ b/doc/examples/animations/README.md @@ -0,0 +1,3 @@ +# animations + +A Flame game showcasing how to use animations diff --git a/doc/examples/animations/assets/images/chopper.png b/doc/examples/animations/assets/images/chopper.png new file mode 100644 index 000000000..7e7d3da5c Binary files /dev/null and b/doc/examples/animations/assets/images/chopper.png differ diff --git a/doc/examples/animations/lib/main.dart b/doc/examples/animations/lib/main.dart new file mode 100644 index 000000000..b9db28144 --- /dev/null +++ b/doc/examples/animations/lib/main.dart @@ -0,0 +1,31 @@ +import 'package:flame/flame.dart'; +import 'package:flame/game.dart'; +import 'package:flame/animation.dart' as FlameAnimation; +import 'package:flame/components/animation_component.dart'; +import 'package:flutter/material.dart'; + +void main() => runApp(MyGame().widget); + +class MyGame extends BaseGame { + MyGame() { + _start(); + } + + _start() async { + Size size = await Flame.util.initialDimensions(); + + final animation = await FlameAnimation.Animation.sequenced('chopper.png', 4, textureWidth: 48, textureHeight: 48, stepTime: 0.15); + + final animationComponent = AnimationComponent(100, 100, animation); + animationComponent.x = size.width / 2 - 100; + animationComponent.y = 100; + + final reversedAnimationComponent = AnimationComponent(100, 100, animation.reversed()); + reversedAnimationComponent.x = size.width / 2; + reversedAnimationComponent.y = 100; + + add(animationComponent); + add(reversedAnimationComponent); + } +} + diff --git a/doc/examples/animations/pubspec.yaml b/doc/examples/animations/pubspec.yaml new file mode 100644 index 000000000..46397c2c5 --- /dev/null +++ b/doc/examples/animations/pubspec.yaml @@ -0,0 +1,21 @@ +name: animations +description: Flame sample game showcasing animations features + +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/chopper.png diff --git a/lib/animation.dart b/lib/animation.dart index a105a50bb..5a10318e9 100644 --- a/lib/animation.dart +++ b/lib/animation.dart @@ -40,12 +40,12 @@ class Animation { /// Creates an animation based on the parameters. /// /// All frames have the same [stepTime]. - Animation.spriteList(List sprites, {double stepTime, this.loop}) { + Animation.spriteList(List sprites, {double stepTime, this.loop = true}) { this.frames = sprites.map((s) => Frame(s, stepTime)).toList(); } /// Creates an animation given a list of frames. - Animation(this.frames, {this.loop}); + Animation(this.frames, {this.loop = true}); /// Automatically creates a sequenced animation, that is, an animation based on a sprite sheet. /// @@ -200,6 +200,11 @@ class Animation { } } + /// Returns a new Animation based on this animation, but with its frames in reversed order + Animation reversed() { + return Animation(this.frames.reversed.toList(), loop: this.loop); + } + /// Wether all sprites composing this animation are loaded. bool loaded() { return frames.every((frame) => frame.sprite.loaded());