Skip to content

Commit

Permalink
Added logic to reset the massNodes' layer if they are resting on the …
Browse files Browse the repository at this point in the history
…shelf. #251
  • Loading branch information
Denz1994 committed May 15, 2018
1 parent 92833ff commit c91bc0b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 14 additions & 1 deletion js/common/model/Mass.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ define( function( require ) {
tandem: tandem.createTandem( 'isAnimatingProperty' )
} );

// @public {Property.<boolean>} indicates whether the mass is resting on its shelf.
this.onShelfProperty = new BooleanProperty( true, {
tandem: tandem.createTandem( 'onShelfProperty' )
} );

// @public {Property.<number>} vertical velocity of mass
this.verticalVelocityProperty = new NumberProperty( 0, {
tandem: tandem.createTandem( 'verticalVelocityProperty' ),
Expand Down Expand Up @@ -232,6 +237,7 @@ define( function( require ) {
self.elasticPotentialEnergyProperty.get() );
}
if ( userControlled ) {
self.onShelfProperty.set(false);
self.verticalVelocityProperty.reset();
}
} );
Expand Down Expand Up @@ -313,6 +319,7 @@ define( function( require ) {
this.animationProgress = 1;
}
if ( this.animationProgress === 1 ) {
this.onShelfProperty.set(true);
this.isAnimatingProperty.set( false );
}
}
Expand All @@ -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 );
Expand All @@ -356,6 +368,7 @@ define( function( require ) {
*/
reset: function() {
this.positionProperty.reset();
this.onShelfProperty.reset();
this.userControlledProperty.reset();
this.springProperty.reset();
this.verticalVelocityProperty.reset();
Expand Down
7 changes: 7 additions & 0 deletions js/common/view/SpringScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
} );
Expand Down

0 comments on commit c91bc0b

Please sign in to comment.