mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 19:12:31 +08:00
The Parallax already supported filter quality, but the loader methods were missing parameters for it to be passed to the loaded instances, making it impossible (unless manually loading) to set a filter quality in a parallax. By setting a filter quality to none (which on flutter means that the next neighbour algorithm will be user) on pixel art sprites we can keep the crisp look that that style of art demands.
82 lines
2.4 KiB
Dart
82 lines
2.4 KiB
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame/parallax.dart';
|
|
import 'package:flutter/painting.dart';
|
|
|
|
class SandboxLayerParallaxExample extends FlameGame {
|
|
static const String description = '''
|
|
In this example, properties of a layer can be changed to preview the
|
|
different combination of values. You can change the properties by pressing
|
|
the pen in the upper right corner.
|
|
''';
|
|
|
|
final Vector2 planeSpeed;
|
|
final ImageRepeat planeRepeat;
|
|
final LayerFill planeFill;
|
|
final Alignment planeAlignment;
|
|
|
|
SandboxLayerParallaxExample({
|
|
required this.planeSpeed,
|
|
required this.planeRepeat,
|
|
required this.planeFill,
|
|
required this.planeAlignment,
|
|
});
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
final bgLayer = await loadParallaxLayer(
|
|
ParallaxImageData('parallax/bg.png'),
|
|
filterQuality: FilterQuality.none,
|
|
);
|
|
final mountainFarLayer = await loadParallaxLayer(
|
|
ParallaxImageData('parallax/mountain-far.png'),
|
|
velocityMultiplier: Vector2(1.8, 0),
|
|
filterQuality: FilterQuality.none,
|
|
);
|
|
final mountainLayer = await loadParallaxLayer(
|
|
ParallaxImageData('parallax/mountains.png'),
|
|
velocityMultiplier: Vector2(2.8, 0),
|
|
filterQuality: FilterQuality.none,
|
|
);
|
|
final treeLayer = await loadParallaxLayer(
|
|
ParallaxImageData('parallax/trees.png'),
|
|
velocityMultiplier: Vector2(3.8, 0),
|
|
filterQuality: FilterQuality.none,
|
|
);
|
|
final foregroundTreesLayer = await loadParallaxLayer(
|
|
ParallaxImageData('parallax/foreground-trees.png'),
|
|
velocityMultiplier: Vector2(4.8, 0),
|
|
filterQuality: FilterQuality.none,
|
|
);
|
|
final airplaneLayer = await loadParallaxLayer(
|
|
ParallaxAnimationData(
|
|
'parallax/airplane.png',
|
|
SpriteAnimationData.sequenced(
|
|
amount: 4,
|
|
stepTime: 0.2,
|
|
textureSize: Vector2(320, 160),
|
|
),
|
|
),
|
|
repeat: planeRepeat,
|
|
velocityMultiplier: planeSpeed,
|
|
fill: planeFill,
|
|
alignment: planeAlignment,
|
|
filterQuality: FilterQuality.none,
|
|
);
|
|
|
|
final parallax = Parallax(
|
|
[
|
|
bgLayer,
|
|
mountainFarLayer,
|
|
mountainLayer,
|
|
treeLayer,
|
|
foregroundTreesLayer,
|
|
airplaneLayer,
|
|
],
|
|
baseVelocity: Vector2(20, 0),
|
|
);
|
|
|
|
add(ParallaxComponent(parallax: parallax));
|
|
}
|
|
}
|