我对基于颤振构建的火焰游戏引擎非常陌生,但我想为我的背景渲染视差图像,但是当我尝试在我的主游戏类中渲染它时它不会出现?
class BackGround extends AnimationComponent {
Rect backgroundRect;
ParallaxComponent _parallaxComponent;
BackGround() : super.empty() {
backgroundRect = Rect.fromLTWH(
100,
100,
100,
100,
);
}
void render(Canvas c) {
_parallaxComponent = ParallaxComponent([
ParallaxImage('Layer_0010_1.png'),
ParallaxImage('Layer_0009_2.png'),
ParallaxImage('Layer_0008_3.png'),
ParallaxImage('Layer_0006_4.png'),
ParallaxImage('Layer_0005_5.png'),
ParallaxImage('Layer_0003_6.png'),
ParallaxImage('Layer_0002_7.png'),
ParallaxImage('Layer_0001_8.png'),
ParallaxImage('Layer_0000_9.png'),
], baseSpeed: Offset(100, 0), layerDelta: Offset(20, 0));
_parallaxComponent.render(c);
}
}
这是我的主要游戏课程的样子。
class MainGame extends BaseGame with TapDetector, HasWidgetsOverlay {
BackGround backback;
Size screenSize;
MainGame(this.storage) {
initialize();
}
void initialize() async {
// resize(await Flame.util.initialDimensions());
backback = BackGround();
}
void render(Canvas c) {
backback.render(c);
}
}