diff --git a/js/game/view/ResultsNode.ts b/js/game/view/ResultsNode.ts index 6c2373b..1e5c9ab 100644 --- a/js/game/view/ResultsNode.ts +++ b/js/game/view/ResultsNode.ts @@ -20,7 +20,7 @@ import GamePhaseNode from './GamePhaseNode.js'; export default class ResultsNode extends GamePhaseNode { - private rewardNode: RPALRewardNode | null; // created on demand + private rewardNode: RPALRewardNode | null; // created dynamically to match the level public constructor( model: GameModel, layoutBounds: Bounds2, audioPlayer: GameAudioPlayer, tandem: Tandem ) { @@ -30,6 +30,9 @@ export default class ResultsNode extends GamePhaseNode { this.rewardNode = null; + // Created dynamically to match the level + let levelCompletedNode: LevelCompletedNode | null = null; + /* * Displays the game results, possibly with a 'reward'. * Unlink is unnecessary because this node exists for the lifetime of the simulation. @@ -49,9 +52,9 @@ export default class ResultsNode extends GamePhaseNode { audioPlayer.gameOverImperfectScore(); } - // game results + // Pseudo-dialog that shows results. const level = model.levelProperty.value; - this.addChild( new LevelCompletedNode( + levelCompletedNode = new LevelCompletedNode( level + 1, model.scoreProperty.value, model.getPerfectScore( level ), @@ -65,14 +68,18 @@ export default class ResultsNode extends GamePhaseNode { starDiameter: 45, centerX: layoutBounds.centerX, centerY: layoutBounds.centerY - } ) ); + } ); + this.addChild( levelCompletedNode ); } else { - this.removeAllChildren(); - if ( this.rewardNode !== null ) { + if ( this.rewardNode ) { this.rewardNode.dispose(); + this.rewardNode = null; + } + if ( levelCompletedNode ) { + levelCompletedNode.dispose(); + levelCompletedNode = null; } - this.rewardNode = null; } } ); }