mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-10-31 17:06:50 +08:00 
			
		
		
		
	 23a72f5f39
			
		
	
	23a72f5f39
	
	
	
		
			
			* No setter for position and size * Use setter for position and size * Add onPositionUpdate and snapTo to Camera * Fix formatting * Fix size in test * Update packages/flame/CHANGELOG.md Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net> * Update packages/flame/CHANGELOG.md Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net> * Better naming for internal position state * Anchor and angle defaults on effect test utils * No setter for position and size * Fix scale effect * Fix formatting Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net> Co-authored-by: Erick Zanardo <erickzanardoo@gmail.com>
		
			
				
	
	
		
			71 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'dart:ui';
 | |
| 
 | |
| import 'package:flame/components.dart';
 | |
| import 'package:flame/game.dart';
 | |
| import 'package:flame/gestures.dart';
 | |
| import 'package:flutter/gestures.dart' show TapDownDetails;
 | |
| 
 | |
| 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(TapDownDetails evt) {
 | |
|     addAnimation(Vector2(evt.globalPosition.dx, evt.globalPosition.dy));
 | |
|   }
 | |
| }
 |