mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +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:
43
doc/examples/parallax/lib/main_advanced.dart
Normal file
43
doc/examples/parallax/lib/main_advanced.dart
Normal file
@ -0,0 +1,43 @@
|
||||
import 'package:flame/flame.dart';
|
||||
import 'package:flame/parallax.dart';
|
||||
import 'package:flame/components/parallax_component.dart';
|
||||
import 'package:flame/extensions/vector2.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Flame.util.fullScreen();
|
||||
runApp(
|
||||
GameWidget(
|
||||
game: MyGame(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class MyGame extends BaseGame {
|
||||
final _layersMeta = {
|
||||
'bg.png': 1.0,
|
||||
'mountain-far.png': 1.5,
|
||||
'mountains.png': 2.3,
|
||||
'trees.png': 3.8,
|
||||
'foreground-trees.png': 6.6,
|
||||
};
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
final layers = _layersMeta.entries.map(
|
||||
(e) => loadParallaxLayer(
|
||||
e.key,
|
||||
velocityMultiplier: Vector2(e.value, 1.0),
|
||||
),
|
||||
);
|
||||
final parallax = ParallaxComponent(
|
||||
Parallax(
|
||||
await Future.wait(layers),
|
||||
baseVelocity: Vector2(20, 0),
|
||||
),
|
||||
);
|
||||
add(parallax);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user