mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-10-31 17:06:50 +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>
		
			
				
	
	
		
			43 lines
		
	
	
		
			912 B
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			912 B
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'package:flame/components.dart';
 | |
| import 'package:flame/flame.dart';
 | |
| import 'package:flame/parallax.dart';
 | |
| import 'package:flame/game.dart';
 | |
| import 'package:flutter/material.dart';
 | |
| 
 | |
| void main() async {
 | |
|   WidgetsFlutterBinding.ensureInitialized();
 | |
|   await Flame.util.fullScreen();
 | |
|   runApp(
 | |
|     GameWidget(
 | |
|       game: MyGame(),
 | |
|     ),
 | |
|   );
 | |
| }
 | |
| 
 | |
| class MyGame extends BaseGame {
 | |
|   final _layersMeta = {
 | |
|     'bg.png': 1.0,
 | |
|     'mountain-far.png': 1.5,
 | |
|     'mountains.png': 2.3,
 | |
|     'trees.png': 3.8,
 | |
|     'foreground-trees.png': 6.6,
 | |
|   };
 | |
| 
 | |
|   @override
 | |
|   Future<void> onLoad() async {
 | |
|     final layers = _layersMeta.entries.map(
 | |
|       (e) => loadParallaxLayer(
 | |
|         e.key,
 | |
|         velocityMultiplier: Vector2(e.value, 1.0),
 | |
|       ),
 | |
|     );
 | |
|     final parallax = ParallaxComponent(
 | |
|       Parallax(
 | |
|         await Future.wait(layers),
 | |
|         baseVelocity: Vector2(20, 0),
 | |
|       ),
 | |
|     );
 | |
|     add(parallax);
 | |
|   }
 | |
| }
 |