Skip to content

Audio

The volume of all sound effects (0.0-1.0).

True while that effect is playing on any channel — handy to avoid restarting a sound that is still running.

  • path (str): audio file, relative to the project folder.

Loads a sound file into the cache and returns the pygame.mixer.Sound — useful to warm up a file before it is needed.

  • path (str): audio file, relative to the project folder.

play_sound(path, volume=1.0, loops=0, fade_ms=0)

Section titled “play_sound(path, volume=1.0, loops=0, fade_ms=0)”

Plays a sound effect and returns its pygame channel (None on failure). Every file is loaded once and reused, so calling it from on_update is fine — a sound is only retriggered from the start once the previous play of that file has finished.

  • path (str): audio file, relative to the project folder.
  • volume (float): playback volume, 0.0-1.0.
  • loops (int): repeats — 0 plays once, -1 loops forever.
  • fade_ms (int): fade-in time in milliseconds.

Sets the volume of all sound effects. It works like the game’s volume slider: it also changes the sounds that are playing right now, and is multiplied with the volume of every later play_sound().

  • volume (float): new master volume, 0.0-1.0.

Stops every effect that is currently playing.

Stops that effect wherever it is playing — a one-shot sound as well as one started with play_sound(..., loops=...).

  • path (str): audio file, relative to the project folder.

The current music volume.

True while a track is playing.

Pauses the current track.

Plays a music track; returns True when playback started. Only one track plays at a time — starting another one replaces it; a new track starts at the volume that was set before.

  • path (str): audio file, relative to the project folder.
  • loops (int): -1 (default) loops forever, 0 plays once.
  • fade_ms (int): fade-in time in milliseconds.

Continues the current track.

Sets the music volume; values outside 0.0-1.0 are clamped.

  • volume (float): new music volume, 0.0-1.0.

Stops the music.

  • fade_ms (int): fade-out time in milliseconds.