mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-07 06:57:22 +08:00
* Adapating ParallaxComponent constructors to other components * Removing wrongly commited folder * Update doc/components.md Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net> * Update doc/components.md Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net> Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>
40 lines
871 B
Dart
40 lines
871 B
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/flame.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame/parallax.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await Flame.device.fullScreen();
|
|
runApp(
|
|
GameWidget(
|
|
game: MyGame(),
|
|
),
|
|
);
|
|
}
|
|
|
|
class MyGame extends BaseGame {
|
|
@override
|
|
Future<void> onLoad() async {
|
|
add(MyParallaxComponent());
|
|
}
|
|
}
|
|
|
|
class MyParallaxComponent extends ParallaxComponent with HasGameRef<MyGame> {
|
|
@override
|
|
Future<void> onLoad() async {
|
|
parallax = await gameRef.loadParallax(
|
|
[
|
|
'bg.png',
|
|
'mountain-far.png',
|
|
'mountains.png',
|
|
'trees.png',
|
|
'foreground-trees.png',
|
|
],
|
|
baseVelocity: Vector2(20, 0),
|
|
velocityMultiplierDelta: Vector2(1.8, 1.0),
|
|
);
|
|
}
|
|
}
|