mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 20:13:50 +08:00
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:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user