mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-01 01:18:38 +08:00 
			
		
		
		
	 8b132d7c0b
			
		
	
	8b132d7c0b
	
	
	
		
			
			* Animations, CameraAndViewport, CollisionDetection and Components unified * Added descriptions to effects * Rename input games * Unify input stories * Add info to parallax section * Added descriptions to the rendering examples * Add descriptions to the sprites directory * Fix utils and rendering section * Add descriptions to the widgets section * Delete directory that rebase brought back * Unify game names * Added some styleguide docs for examples * Fix analyze issues * All files should have _example as suffix * Made the FollowComponentExample a bit easier to understand * Change priority of ember
		
			
				
	
	
		
			77 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			77 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| import 'package:flame/components.dart';
 | |
| import 'package:flame/game.dart';
 | |
| import 'package:flame/parallax.dart';
 | |
| import 'package:flutter/painting.dart';
 | |
| 
 | |
| class SandboxLayerParallaxExample extends FlameGame {
 | |
|   static const String description = '''
 | |
|     In this example, properties of a layer can be changed to preview the
 | |
|     different combination of values. You can change the properties by pressing
 | |
|     the pen in the upper right corner.
 | |
|   ''';
 | |
| 
 | |
|   final Vector2 planeSpeed;
 | |
|   final ImageRepeat planeRepeat;
 | |
|   final LayerFill planeFill;
 | |
|   final Alignment planeAlignment;
 | |
| 
 | |
|   SandboxLayerParallaxExample({
 | |
|     required this.planeSpeed,
 | |
|     required this.planeRepeat,
 | |
|     required this.planeFill,
 | |
|     required this.planeAlignment,
 | |
|   });
 | |
| 
 | |
|   @override
 | |
|   Future<void> onLoad() async {
 | |
|     await super.onLoad();
 | |
|     final bgLayer = await loadParallaxLayer(
 | |
|       ParallaxImageData('parallax/bg.png'),
 | |
|     );
 | |
|     final mountainFarLayer = await loadParallaxLayer(
 | |
|       ParallaxImageData('parallax/mountain-far.png'),
 | |
|       velocityMultiplier: Vector2(1.8, 0),
 | |
|     );
 | |
|     final mountainLayer = await loadParallaxLayer(
 | |
|       ParallaxImageData('parallax/mountains.png'),
 | |
|       velocityMultiplier: Vector2(2.8, 0),
 | |
|     );
 | |
|     final treeLayer = await loadParallaxLayer(
 | |
|       ParallaxImageData('parallax/trees.png'),
 | |
|       velocityMultiplier: Vector2(3.8, 0),
 | |
|     );
 | |
|     final foregroundTreesLayer = await loadParallaxLayer(
 | |
|       ParallaxImageData('parallax/foreground-trees.png'),
 | |
|       velocityMultiplier: Vector2(4.8, 0),
 | |
|     );
 | |
|     final airplaneLayer = await loadParallaxLayer(
 | |
|       ParallaxAnimationData(
 | |
|         'parallax/airplane.png',
 | |
|         SpriteAnimationData.sequenced(
 | |
|           amount: 4,
 | |
|           stepTime: 0.2,
 | |
|           textureSize: Vector2(320, 160),
 | |
|         ),
 | |
|       ),
 | |
|       repeat: planeRepeat,
 | |
|       velocityMultiplier: planeSpeed,
 | |
|       fill: planeFill,
 | |
|       alignment: planeAlignment,
 | |
|     );
 | |
| 
 | |
|     final parallax = Parallax(
 | |
|       [
 | |
|         bgLayer,
 | |
|         mountainFarLayer,
 | |
|         mountainLayer,
 | |
|         treeLayer,
 | |
|         foregroundTreesLayer,
 | |
|         airplaneLayer,
 | |
|       ],
 | |
|       baseVelocity: Vector2(20, 0),
 | |
|     );
 | |
| 
 | |
|     add(ParallaxComponent(parallax: parallax));
 | |
|   }
 | |
| }
 |