From c91bc0b5f0518b3863f1a781ab02eada91c1290c Mon Sep 17 00:00:00 2001 From: denz1994 Date: Tue, 15 May 2018 13:43:02 -0400 Subject: [PATCH] Added logic to reset the massNodes' layer if they are resting on the shelf. #251 --- js/common/model/Mass.js | 15 ++++++++++++++- js/common/view/SpringScreenView.js | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/js/common/model/Mass.js b/js/common/model/Mass.js index 6164952d..d1867c3d 100644 --- a/js/common/model/Mass.js +++ b/js/common/model/Mass.js @@ -122,6 +122,11 @@ define( function( require ) { tandem: tandem.createTandem( 'isAnimatingProperty' ) } ); + // @public {Property.} indicates whether the mass is resting on its shelf. + this.onShelfProperty = new BooleanProperty( true, { + tandem: tandem.createTandem( 'onShelfProperty' ) + } ); + // @public {Property.} vertical velocity of mass this.verticalVelocityProperty = new NumberProperty( 0, { tandem: tandem.createTandem( 'verticalVelocityProperty' ), @@ -232,6 +237,7 @@ define( function( require ) { self.elasticPotentialEnergyProperty.get() ); } if ( userControlled ) { + self.onShelfProperty.set(false); self.verticalVelocityProperty.reset(); } } ); @@ -313,6 +319,7 @@ define( function( require ) { this.animationProgress = 1; } if ( this.animationProgress === 1 ) { + this.onShelfProperty.set(true); this.isAnimatingProperty.set( false ); } } @@ -332,7 +339,12 @@ define( function( require ) { this.animationProgress = 0; this.animationStartPosition = this.positionProperty.value; this.animationEndPosition = new Vector2( this.initialPosition.x, this.positionProperty.value.y ); - this.isAnimatingProperty.set( true ); + if ( this.animationStartPosition.distance( this.animationEndPosition ) >= 1e-7 ) { + this.isAnimatingProperty.set( true ); + } + else { + this.onShelfProperty.set( true ); + } } else { this.verticalVelocityProperty.set( newVerticalVelocity ); @@ -356,6 +368,7 @@ define( function( require ) { */ reset: function() { this.positionProperty.reset(); + this.onShelfProperty.reset(); this.userControlledProperty.reset(); this.springProperty.reset(); this.verticalVelocityProperty.reset(); diff --git a/js/common/view/SpringScreenView.js b/js/common/view/SpringScreenView.js index 5b51108f..996771f5 100644 --- a/js/common/view/SpringScreenView.js +++ b/js/common/view/SpringScreenView.js @@ -99,6 +99,13 @@ define( function( require ) { tandem.createTandem( mass.massTandem.tail + 'Node' ) ); self.massLayer.addChild( massNode ); + // If we are the shelf reset the mass layers. + mass.onShelfProperty.lazyLink( function( onShelf ) { + if ( onShelf ) { + self.resetMassLayer(); + } + } ); + // Keeps track of the mass node to restore original Z order. return massNode; } );