mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-01 01:18:38 +08:00 
			
		
		
		
	 defcb456e1
			
		
	
	defcb456e1
	
	
	
		
			
			* Adding SpriteAnimationGroupComponent * adding tests * Changing ci to use flutter stable * Addressing Spydon's comments * reverting analysis_options.yml * linting
		
			
				
	
	
		
			66 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'dart:ui';
 | |
| 
 | |
| import 'package:flame/components.dart';
 | |
| import 'package:flame/game.dart';
 | |
| import 'package:flame/gestures.dart';
 | |
| 
 | |
| enum RobotState {
 | |
|   idle,
 | |
|   running,
 | |
| }
 | |
| 
 | |
| class AnimationGroupExample extends BaseGame with TapDetector {
 | |
|   late SpriteAnimationGroupComponent robot;
 | |
| 
 | |
|   @override
 | |
|   Future<void> onLoad() async {
 | |
|     final running = await loadSpriteAnimation(
 | |
|       'animations/robot.png',
 | |
|       SpriteAnimationData.sequenced(
 | |
|         amount: 8,
 | |
|         stepTime: 0.2,
 | |
|         textureSize: Vector2(16, 18),
 | |
|       ),
 | |
|     );
 | |
|     final idle = await loadSpriteAnimation(
 | |
|       'animations/robot-idle.png',
 | |
|       SpriteAnimationData.sequenced(
 | |
|         amount: 4,
 | |
|         stepTime: 0.4,
 | |
|         textureSize: Vector2(16, 18),
 | |
|       ),
 | |
|     );
 | |
| 
 | |
|     final robotSize = Vector2(64, 72);
 | |
|     robot = SpriteAnimationGroupComponent<RobotState>(
 | |
|       animations: {
 | |
|         RobotState.running: running,
 | |
|         RobotState.idle: idle,
 | |
|       },
 | |
|       current: RobotState.idle,
 | |
|       position: size / 2 - robotSize / 2,
 | |
|       size: robotSize,
 | |
|     );
 | |
| 
 | |
|     add(robot);
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   void onTapDown(_) {
 | |
|     robot.current = RobotState.running;
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   void onTapCancel() {
 | |
|     robot.current = RobotState.idle;
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   void onTapUp(_) {
 | |
|     robot.current = RobotState.idle;
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   Color backgroundColor() => const Color(0xFF222222);
 | |
| }
 |