mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
Parallax background example game
This commit is contained in:
26
doc/examples/parallax/lib/main.dart
Normal file
26
doc/examples/parallax/lib/main.dart
Normal file
@ -0,0 +1,26 @@
|
||||
import 'package:flame/flame.dart';
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flame/components/parallax_component.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() async {
|
||||
await Flame.util.fullScreen();
|
||||
runApp(MyGame().widget);
|
||||
}
|
||||
|
||||
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 parallaxComponent = ParallaxComponent(images,
|
||||
baseSpeed: const Offset(20, 0), layerDelta: const Offset(30, 0));
|
||||
|
||||
add(parallaxComponent);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user