mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
Adding Animation reversed (#66)
* Adding Animation#reversed * Updating CHANGELOG * PR suggestions
This commit is contained in:
@ -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
|
||||
|
||||
70
doc/examples/animations/.gitignore
vendored
Normal file
70
doc/examples/animations/.gitignore
vendored
Normal file
@ -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
|
||||
10
doc/examples/animations/.metadata
Normal file
10
doc/examples/animations/.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/animations/README.md
Normal file
3
doc/examples/animations/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# animations
|
||||
|
||||
A Flame game showcasing how to use animations
|
||||
BIN
doc/examples/animations/assets/images/chopper.png
Normal file
BIN
doc/examples/animations/assets/images/chopper.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
31
doc/examples/animations/lib/main.dart
Normal file
31
doc/examples/animations/lib/main.dart
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
21
doc/examples/animations/pubspec.yaml
Normal file
21
doc/examples/animations/pubspec.yaml
Normal file
@ -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
|
||||
@ -40,12 +40,12 @@ class Animation {
|
||||
/// Creates an animation based on the parameters.
|
||||
///
|
||||
/// All frames have the same [stepTime].
|
||||
Animation.spriteList(List<Sprite> sprites, {double stepTime, this.loop}) {
|
||||
Animation.spriteList(List<Sprite> 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());
|
||||
|
||||
Reference in New Issue
Block a user