fix: set fpsComponent only for debug game

pull/498/head
Hugo Walbecq 3 years ago committed by Hugo Walbecq
parent d3e21d07cb
commit c69d632028

@ -100,7 +100,6 @@ class PinballGame extends PinballForge2DGame
FlameProvider<PlatformHelper>.value(platformHelper), FlameProvider<PlatformHelper>.value(platformHelper),
], ],
children: [ children: [
FpsComponent(),
BonusNoiseBehavior(), BonusNoiseBehavior(),
GameBlocStatusListener(), GameBlocStatusListener(),
BallSpawningBehavior(), BallSpawningBehavior(),
@ -239,7 +238,12 @@ class DebugPinballGame extends PinballGame with PanDetector {
@override @override
Future<void> onLoad() async { Future<void> onLoad() async {
await super.onLoad(); await super.onLoad();
await addAll([PreviewLine(), _DebugInformation()]); final fpsComponent = FpsComponent();
await addAll([
PreviewLine(),
fpsComponent,
_DebugInformation(fpsComponent: fpsComponent)
]);
} }
@override @override
@ -300,6 +304,7 @@ class PreviewLine extends PositionComponent with HasGameRef<DebugPinballGame> {
} }
class _DebugInformation extends Component with HasGameRef<DebugPinballGame> { class _DebugInformation extends Component with HasGameRef<DebugPinballGame> {
_DebugInformation({required this.fpsComponent});
@override @override
PositionType get positionType => PositionType.widget; PositionType get positionType => PositionType.widget;
@ -311,11 +316,12 @@ class _DebugInformation extends Component with HasGameRef<DebugPinballGame> {
); );
final _debugBackgroundPaint = Paint()..color = Colors.white; final _debugBackgroundPaint = Paint()..color = Colors.white;
final FpsComponent fpsComponent;
@override @override
void render(Canvas canvas) { void render(Canvas canvas) {
final debugText = [ final debugText = [
'FPS: ${gameRef.descendants().whereType<FpsComponent>().first.fps}', 'FPS: ${fpsComponent.fps}',
'BALLS: ${gameRef.descendants().whereType<Ball>().length}', 'BALLS: ${gameRef.descendants().whereType<Ball>().length}',
].join(' | '); ].join(' | ');

Loading…
Cancel
Save