Refactor ParallaxComponent (#613)

* Simplified loading of ParallaxComponent

* Loading helpers for the different Parallax parts

And refactor how the delta velocity works

* Fix formatting

* Break out Parallax out of ParallaxComponent

* Fix docs

* Add extension for loading different parallax things on game

* Fix formatting

* Add loadParallaxComponent extension

* Fix formatting
This commit is contained in:
Lukas Klingsbo
2021-01-06 21:07:31 +01:00
committed by GitHub
parent 0b6efdf170
commit af53438cd4
6 changed files with 497 additions and 212 deletions

View File

@ -15,21 +15,22 @@ void main() async {
}
class MyGame extends BaseGame {
MyGame() {
final images = [
ParallaxImage('bg.png'),
ParallaxImage('mountain-far.png'),
ParallaxImage('mountains.png'),
ParallaxImage('trees.png'),
ParallaxImage('foreground-trees.png'),
];
final _imageNames = [
'bg.png',
'mountain-far.png',
'mountains.png',
'trees.png',
'foreground-trees.png',
];
final parallaxComponent = ParallaxComponent(
images,
baseSpeed: Vector2(20, 0),
layerDelta: Vector2(30, 0),
@override
Future<void> onLoad() async {
final parallax = await ParallaxComponent.load(
_imageNames,
baseVelocity: Vector2(20, 0),
velocityMultiplierDelta: Vector2(1.8, 1.0),
images: images,
);
add(parallaxComponent);
add(parallax);
}
}