From 9372977c60a5f70a47f71a0d422d2eb0f43a9db6 Mon Sep 17 00:00:00 2001 From: pixelzoom Date: Tue, 17 Dec 2024 16:30:46 -0700 Subject: [PATCH] step the view only if the sim is playing, https://github.com/phetsims/models-of-the-hydrogen-atom/issues/33 --- js/energylevels/view/EnergyLevelsScreenView.ts | 8 ++++++-- js/spectra/view/SpectraScreenView.ts | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/js/energylevels/view/EnergyLevelsScreenView.ts b/js/energylevels/view/EnergyLevelsScreenView.ts index 097260b5..f61f339e 100644 --- a/js/energylevels/view/EnergyLevelsScreenView.ts +++ b/js/energylevels/view/EnergyLevelsScreenView.ts @@ -36,6 +36,7 @@ import EnergyLevelsZoomedInBoxNode from './EnergyLevelsZoomedInBoxNode.js'; export default class EnergyLevelsScreenView extends ScreenView { + private readonly model: EnergyLevelsModel; private readonly zoomedInBoxNode: EnergyLevelsZoomedInBoxNode; private readonly electronEnergyLevelAccordionBox: ElectronEnergyLevelAccordionBox; @@ -236,13 +237,16 @@ export default class EnergyLevelsScreenView extends ScreenView { resetAllButton ]; + this.model = model; this.zoomedInBoxNode = zoomedInBoxNode; this.electronEnergyLevelAccordionBox = electronEnergyLevelAccordionBox; } public override step( dt: number ): void { - this.zoomedInBoxNode.step( dt ); - this.electronEnergyLevelAccordionBox.step( dt ); + if ( this.model.isPlayingProperty.value ) { + this.zoomedInBoxNode.step( dt ); + this.electronEnergyLevelAccordionBox.step( dt ); + } } } diff --git a/js/spectra/view/SpectraScreenView.ts b/js/spectra/view/SpectraScreenView.ts index 709f7257..72cb9bef 100644 --- a/js/spectra/view/SpectraScreenView.ts +++ b/js/spectra/view/SpectraScreenView.ts @@ -34,6 +34,7 @@ import SpectraZoomedInBoxNode from './SpectraZoomedInBoxNode.js'; export default class SpectraScreenView extends ScreenView { + private readonly model: SpectraModel; private readonly zoomedInBoxNode: SpectraZoomedInBoxNode; public constructor( model: SpectraModel, tandem: Tandem ) { @@ -223,11 +224,14 @@ export default class SpectraScreenView extends ScreenView { resetAllButton ]; + this.model = model; this.zoomedInBoxNode = zoomedInBoxNode; } public override step( dt: number ): void { - this.zoomedInBoxNode.step( dt ); + if ( this.model.isPlayingProperty.value ) { + this.zoomedInBoxNode.step( dt ); + } } }