mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-04 13:08:09 +08:00 
			
		
		
		
	* some initial refactoring * Fixing examples and joystick component * Fixing examples * Addressing comments from PR * Fixing tutorials * Updating docs * Fixing tests * PR followup * A big follow up * linting * doc nit * Changelog and fix tutorial * Addressing comments * Fixing BaseGame project and scale offset methods * Formatting * doc suggestions * Update packages/flame/lib/src/gestures/events.dart Co-authored-by: Luan Nico <luanpotter27@gmail.com> * Hopefully, the last follow up * Linting and adding dart-code-metrics again * fixing tutorial Co-authored-by: Luan Nico <luanpotter27@gmail.com>
		
			
				
	
	
		
			70 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			70 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
import 'dart:ui';
 | 
						|
 | 
						|
import 'package:flame/components.dart';
 | 
						|
import 'package:flame/game.dart';
 | 
						|
import 'package:flame/gestures.dart';
 | 
						|
 | 
						|
class BasicAnimations extends BaseGame with TapDetector {
 | 
						|
  late Image chopper;
 | 
						|
  late Image creature;
 | 
						|
  late SpriteAnimation animation;
 | 
						|
 | 
						|
  @override
 | 
						|
  Future<void> onLoad() async {
 | 
						|
    chopper = await images.load('animations/chopper.png');
 | 
						|
    creature = await images.load('animations/creature.png');
 | 
						|
 | 
						|
    animation = SpriteAnimation.fromFrameData(
 | 
						|
      chopper,
 | 
						|
      SpriteAnimationData.sequenced(
 | 
						|
        amount: 4,
 | 
						|
        textureSize: Vector2.all(48),
 | 
						|
        stepTime: 0.15,
 | 
						|
      ),
 | 
						|
    );
 | 
						|
 | 
						|
    final spriteSize = Vector2.all(100.0);
 | 
						|
    final animationComponent2 = SpriteAnimationComponent(
 | 
						|
      animation: animation,
 | 
						|
      size: spriteSize,
 | 
						|
    );
 | 
						|
    animationComponent2.x = size.x / 2 - spriteSize.x;
 | 
						|
    animationComponent2.y = spriteSize.y;
 | 
						|
 | 
						|
    final reversedAnimationComponent = SpriteAnimationComponent(
 | 
						|
      animation: animation.reversed(),
 | 
						|
      size: spriteSize,
 | 
						|
    );
 | 
						|
    reversedAnimationComponent.x = size.x / 2;
 | 
						|
    reversedAnimationComponent.y = spriteSize.y;
 | 
						|
 | 
						|
    add(animationComponent2);
 | 
						|
    add(reversedAnimationComponent);
 | 
						|
  }
 | 
						|
 | 
						|
  void addAnimation(Vector2 position) {
 | 
						|
    final size = Vector2(291, 178);
 | 
						|
 | 
						|
    final animationComponent = SpriteAnimationComponent.fromFrameData(
 | 
						|
      creature,
 | 
						|
      SpriteAnimationData.sequenced(
 | 
						|
        amount: 18,
 | 
						|
        amountPerRow: 10,
 | 
						|
        textureSize: size,
 | 
						|
        stepTime: 0.15,
 | 
						|
        loop: false,
 | 
						|
      ),
 | 
						|
      size: size,
 | 
						|
      removeOnFinish: true,
 | 
						|
    );
 | 
						|
 | 
						|
    animationComponent.position = position - size / 2;
 | 
						|
    add(animationComponent);
 | 
						|
  }
 | 
						|
 | 
						|
  @override
 | 
						|
  void onTapDown(TapDownInfo event) {
 | 
						|
    addAnimation(event.eventPosition.game);
 | 
						|
  }
 | 
						|
}
 |