mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-01 01:18:38 +08:00 
			
		
		
		
	 ccee9a466b
			
		
	
	ccee9a466b
	
	
	
		
			
			* 👌 Use `Offset` type directly in `JoystickAction.update` calculations (#631) * Move files to src and comply with the dart package layout convention * Fixing widgets example Co-authored-by: Serge Matveenko <lig@countzero.co> Co-authored-by: Erick Zanardo <erickzanardoo@gmail.com>
		
			
				
	
	
		
			58 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'package:flame/components.dart';
 | |
| import 'package:flame/game.dart';
 | |
| import 'package:flame/spritesheet.dart';
 | |
| import 'package:flutter/material.dart';
 | |
| 
 | |
| void main() async {
 | |
|   WidgetsFlutterBinding.ensureInitialized();
 | |
| 
 | |
|   runApp(
 | |
|     GameWidget(
 | |
|       game: MyGame(),
 | |
|     ),
 | |
|   );
 | |
| }
 | |
| 
 | |
| class MyGame extends BaseGame {
 | |
|   @override
 | |
|   Future<void> onLoad() async {
 | |
|     final spriteSheet = SpriteSheet(
 | |
|       image: await images.load('spritesheet.png'),
 | |
|       srcSize: Vector2(16.0, 18.0),
 | |
|     );
 | |
| 
 | |
|     final vampireAnimation =
 | |
|         spriteSheet.createAnimation(row: 0, stepTime: 0.1, to: 7);
 | |
|     final ghostAnimation =
 | |
|         spriteSheet.createAnimation(row: 1, stepTime: 0.1, to: 7);
 | |
|     final spriteSize = Vector2(80.0, 90.0);
 | |
| 
 | |
|     final vampireComponent = SpriteAnimationComponent.fromSpriteAnimation(
 | |
|         spriteSize, vampireAnimation)
 | |
|       ..x = 150
 | |
|       ..y = 100;
 | |
| 
 | |
|     final ghostComponent =
 | |
|         SpriteAnimationComponent.fromSpriteAnimation(spriteSize, ghostAnimation)
 | |
|           ..x = 150
 | |
|           ..y = 220;
 | |
| 
 | |
|     add(vampireComponent);
 | |
|     add(ghostComponent);
 | |
| 
 | |
|     // Some plain sprites
 | |
|     final vampireSpriteComponent =
 | |
|         SpriteComponent.fromSprite(spriteSize, spriteSheet.getSprite(0, 0))
 | |
|           ..x = 50
 | |
|           ..y = 100;
 | |
| 
 | |
|     final ghostSpriteComponent =
 | |
|         SpriteComponent.fromSprite(spriteSize, spriteSheet.getSprite(1, 0))
 | |
|           ..x = 50
 | |
|           ..y = 220;
 | |
| 
 | |
|     add(vampireSpriteComponent);
 | |
|     add(ghostSpriteComponent);
 | |
|   }
 | |
| }
 |