Skip to content

Commit

Permalink
call ChallengeNode.dispose when challenge changes, #78
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Apr 23, 2017
1 parent 2baf6d8 commit 896e910
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions js/linegame/view/PlayNode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2013-2015, University of Colorado Boulder
// Copyright 2013-2017, University of Colorado Boulder

/**
* Portion of the scenegraph that corresponds to the 'play' game phase. (See GamePhase.PLAY)
Expand All @@ -10,6 +10,7 @@ define( function( require ) {
'use strict';

// modules
var ChallengeNode = require( 'GRAPHING_LINES/linegame/view/ChallengeNode' );
var Dimension2 = require( 'DOT/Dimension2' );
var GamePhase = require( 'GRAPHING_LINES/linegame/model/GamePhase' );
var GLFont = require( 'GRAPHING_LINES/common/GLFont' );
Expand Down Expand Up @@ -59,8 +60,17 @@ define( function( require ) {

// Set up a new challenge
model.challengeProperty.link( function( challenge ) {
//TODO #78 call dispose on ChallengeNode subtypes
challengeParent.removeAllChildren();

// dispose of view for previous challenge
var challengeNodes = challengeParent.getChildren();
for ( var i = 0; i < challengeNodes.length; i++ ) {
var challengeNode = challengeNodes[ i ];
assert && assert( challengeNode instanceof ChallengeNode );
challengeNode.dispose();
challengeParent.removeChild( challengeNode );
}

// add view for current challenge
challengeParent.addChild( challenge.createView( model, challengeSize, audioPlayer ) );
} );
}
Expand Down

0 comments on commit 896e910

Please sign in to comment.