Created
March 3, 2023 14:14
-
-
Save vbalagovic/ac7e32c0ed8b87f2f67efa8b1715c830 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Added World | |
import 'package:flame/components.dart'; | |
import 'package:flame/parallax.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter_flame_showcase/main.dart'; | |
class MkWorld extends ParallaxComponent<MortalKombat> { | |
@override | |
Future<void> onLoad() async { | |
// Images with custom fill and repeat | |
final images = [ | |
gameRef.loadParallaxImage('p_bg.png', fill: LayerFill.height, repeat: ImageRepeat.repeatX, alignment: Alignment.topLeft), | |
gameRef.loadParallaxImage('p_4.png', fill: LayerFill.width, repeat: ImageRepeat.noRepeat), | |
gameRef.loadParallaxImage('p_3.png', fill: LayerFill.width, repeat: ImageRepeat.noRepeat), | |
gameRef.loadParallaxImage('p_2.gif', fill: LayerFill.width, repeat: ImageRepeat.noRepeat), | |
gameRef.loadParallaxImage('p_1.gif', fill: LayerFill.width, repeat: ImageRepeat.noRepeat), | |
]; | |
// Layers with custom velocity | |
final layers = images.map((image) async => ParallaxLayer( | |
await image, | |
velocityMultiplier: images.indexOf(image) == 0 ? Vector2(20, 0) : Vector2(0, 0), | |
)); | |
// Create parallax | |
final parallaxComponent = ParallaxComponent( | |
parallax: Parallax( | |
await Future.wait(layers), | |
baseVelocity: Vector2(1, 0), | |
), | |
); | |
// Add parallax to game | |
parallax = parallaxComponent.parallax; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment