Skip to content

Commit 00000b9

Browse files
committed
Added simple Play method
1 parent c12a06b commit 00000b9

File tree

1 file changed

+13
-3
lines changed
  • articles/tutorials/building_2d_games/12_soundeffects_and_music

1 file changed

+13
-3
lines changed

articles/tutorials/building_2d_games/12_soundeffects_and_music/index.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,25 @@ Add the following methods to control audio playback:
375375

376376
```cs
377377
/// <summary>
378-
/// Plays the sound effect with the specified asset name.
378+
/// Plays the sound effect with the specified name.
379+
/// </summary>
380+
/// <param name="assetName">The asset name of the sound effect to play.</param>
381+
/// <returns>The sound effect instance created by playing the sound effect.</returns>
382+
public SoundEffectInstance PlaySoundEffect(string assetName)
383+
{
384+
return PlaySoundEffect(assetName, 1.0f, 0.0f, 0.0f, false);
385+
}
386+
387+
/// <summary>
388+
/// Plays the sound effect with the specified asset name, using the specified properties.
379389
/// </summary>
380390
/// <param name="assetName">The asset name of the sound effect to play.</param>
381391
/// <param name="volume">The volume, ranging from 0.0 (silence) to 1.0 (full volume).</param>
382392
/// <param name="pitch">The pitch adjustment, ranging from -1.0 (down an octave) to 0.0 (no change) to 1.0 (up an octave).</param>
383393
/// <param name="pan">The panning, ranging from -1.0 (left speaker) to 0.0 (centered), 1.0 (right speaker).</param>
384394
/// <param name="isLooped">Whether the the sound effect should loop after playback.</param>
385395
/// <returns>The sound effect instance created by playing the sound effect.</returns>
386-
public SoundEffectInstance PlaySoundEffect(string assetName, float volume = 1.0f, float pitch = 0.0f, float pan = 0.0f, bool isLooped = false)
396+
public SoundEffectInstance PlaySoundEffect(string assetName, float volume, float pitch, float pan, bool isLooped)
387397
{
388398
SoundEffect soundEffect = _soundEffects[assetName];
389399

@@ -416,7 +426,7 @@ public void PlaySong(string assetName)
416426
}
417427
```
418428

419-
- `PlaySoundEffect`: Creates and plays an instance of a sound effect with customizable properties like volume, pitch, panning, and looping. Returns the instance for further control if needed.
429+
- `PlaySoundEffect`: Two overloads of this method are implemented. The first can be used to quickly fire off a sound effect if you don't need to adjust additional properties. The second contains parameters to customize the volume, pitch, panning, and looping properties of the sound effect. Both methods returns the instance for further control if needed.
420430
- `PlaySong`: Starts playing a song through the MediaPlayer. Since only one song can play at a time, this will automatically stop any currently playing song.
421431

422432
#### State Control Methods

0 commit comments

Comments
 (0)