Skip to content

Commit

Permalink
play grab/release sounds on group sort interactions, see #190
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Jun 7, 2024
1 parent 0389076 commit e28abbe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion js/common/MeanShareAndBalanceConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ const MeanShareAndBalanceConstants = {
CHART_VIEW_WIDTH: ScreenView.DEFAULT_LAYOUT_BOUNDS.width - CONTROLS_PREFERRED_WIDTH
- NUMBER_LINE_LEFT_X_MARGIN - NUMBER_LINE_RIGHT_X_MARGIN,
FULCRUM_DEFAULT_POSITION: 5,
FULCRUM_ICON_TRIANGLE_DIMENSIONS: { triangleHeight: 22, triangleWidth: 24 }
FULCRUM_ICON_TRIANGLE_DIMENSIONS: { triangleHeight: 22, triangleWidth: 24 },
GRAB_RELEASE_SOUND_LEVEL: 0.25
};

meanShareAndBalance.register( 'MeanShareAndBalanceConstants', MeanShareAndBalanceConstants );
Expand Down
16 changes: 15 additions & 1 deletion js/distribute/view/DistributeScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import ResetAllButton from '../../../../scenery-phet/js/buttons/ResetAllButton.j
import soundManager from '../../../../tambo/js/soundManager.js';
import dragIndicatorHand_png from '../../../../scenery-phet/images/dragIndicatorHand_png.js';
import Snack from '../../common/model/Snack.js';
import grabCandyBarV2_mp3 from '../../../sounds/grabCandyBarV2_mp3.js';
import releaseCandyBarV2_mp3 from '../../../sounds/releaseCandyBarV2_mp3.js';

type SelfOptions = EmptySelfOptions;
type DistributeScreenViewOptions = SelfOptions & StrictOmit<SharingScreenViewOptions, 'children' | 'snackType'>;
Expand Down Expand Up @@ -261,6 +263,16 @@ export default class DistributeScreenView extends SharingScreenView<Snack> {
} );
this.notepadSnackLayerNode.addChild( meanPredictionSlider );

// Create sound players from grab and release during group sort interactions.
const grabSoundClip = new SoundClip( grabCandyBarV2_mp3, {
initialOutputLevel: MeanShareAndBalanceConstants.GRAB_RELEASE_SOUND_LEVEL
} );
soundManager.addSoundGenerator( grabSoundClip );
const releaseSoundClip = new SoundClip( releaseCandyBarV2_mp3, {
initialOutputLevel: MeanShareAndBalanceConstants.GRAB_RELEASE_SOUND_LEVEL
} );
soundManager.addSoundGenerator( releaseSoundClip );

this.groupSortInteractionView = new GroupSortInteractionView(
model.groupSortInteractionModel,
notepadCandyBarsHighlightNode,
Expand Down Expand Up @@ -308,7 +320,9 @@ export default class DistributeScreenView extends SharingScreenView<Snack> {
// Remove the candy bar from the current plate and add it to the top of the new plate.
currentPlate!.removeSnack( candyBar );
newPlate.addSnackToTop( candyBar );
}
},
onGrab: () => grabSoundClip.play(),
onRelease: () => releaseSoundClip.play()
}
);

Expand Down
4 changes: 2 additions & 2 deletions js/distribute/view/NotepadCandyBarNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ export default class NotepadCandyBarNode extends InteractiveHighlighting( Node )

this.dragListener = new RichPointerDragListener( {
grabSound: grabCandyBarV2_mp3,
grabSoundClipOptions: { initialOutputLevel: 0.25 },
grabSoundClipOptions: { initialOutputLevel: MeanShareAndBalanceConstants.GRAB_RELEASE_SOUND_LEVEL },
releaseSound: releaseCandyBarV2_mp3,
releaseSoundClipOptions: { initialOutputLevel: 0.25 },
releaseSoundClipOptions: { initialOutputLevel: MeanShareAndBalanceConstants.GRAB_RELEASE_SOUND_LEVEL },
transform: modelViewTransform,
positionProperty: this.candyBar.positionProperty,
offsetPosition: ( viewPoint, dragListener ) => {
Expand Down

0 comments on commit e28abbe

Please sign in to comment.