mirror of
https://github.com/flame-engine/flame.git
synced 2025-10-30 16:36:57 +08:00
* Adding animation support to parallax * Solving workaround * Fixing image composition add assert * adding docs, linting and a better example * lint * Apply suggestions from code review Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net> * Update examples/lib/stories/parallax/sandbox_layer.dart * Update doc/components.md * Update examples/lib/stories/parallax/sandbox_layer.dart Co-authored-by: Luan Nico <luanpotter27@gmail.com> * Update examples/lib/stories/parallax/animation.dart * formating * Update .min_coverage Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net> Co-authored-by: Luan Nico <luanpotter27@gmail.com>
45 lines
1.1 KiB
Dart
45 lines
1.1 KiB
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame/parallax.dart';
|
|
import 'package:flutter/painting.dart';
|
|
|
|
class AnimationParallaxGame extends BaseGame {
|
|
@override
|
|
Future<void> onLoad() async {
|
|
final cityLayer = await loadParallaxLayer(
|
|
ParallaxImageData('parallax/city.png'),
|
|
);
|
|
|
|
final rainLayer = await loadParallaxLayer(
|
|
ParallaxAnimationData(
|
|
'parallax/rain.png',
|
|
SpriteAnimationData.sequenced(
|
|
amount: 4,
|
|
stepTime: 0.3,
|
|
textureSize: Vector2(80, 160),
|
|
),
|
|
),
|
|
velocityMultiplier: Vector2(2, 0),
|
|
);
|
|
|
|
final cloudsLayer = await loadParallaxLayer(
|
|
ParallaxImageData('parallax/heavy_clouded.png'),
|
|
velocityMultiplier: Vector2(4, 0),
|
|
fill: LayerFill.none,
|
|
alignment: Alignment.topLeft,
|
|
);
|
|
|
|
final parallax = Parallax(
|
|
[
|
|
cityLayer,
|
|
rainLayer,
|
|
cloudsLayer,
|
|
],
|
|
baseVelocity: Vector2(20, 0),
|
|
);
|
|
|
|
final parallaxComponent = ParallaxComponent.fromParallax(parallax);
|
|
add(parallaxComponent);
|
|
}
|
|
}
|