mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-05 13:37:28 +08:00
* 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
37 lines
798 B
Dart
37 lines
798 B
Dart
import 'package:flame/flame.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 _imageNames = [
|
|
'bg.png',
|
|
'mountain-far.png',
|
|
'mountains.png',
|
|
'trees.png',
|
|
'foreground-trees.png',
|
|
];
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
final parallax = await ParallaxComponent.load(
|
|
_imageNames,
|
|
baseVelocity: Vector2(20, 0),
|
|
velocityMultiplierDelta: Vector2(1.8, 1.0),
|
|
images: images,
|
|
);
|
|
add(parallax);
|
|
}
|
|
}
|