Music and SoundFx

The Music and Sound players allow the user to play their desired music or sounds in the game. By default, there are 16 channels available to the user to use. There is only one channel that is dedicated for music, meaning that we can only have one music song playing at a time.

Music Player

The music player will only play sounds that have already been loaded into the Asset Manager. The music player is automatically opened when the engine boots up.

  • Valid music file formats:
    • MP3
    • WAV
    • OGG

Functions:

play

FunctionDescription
play(string, int)The play function takes in a string for the music name to be played and an int value for the number of loops. To loop indefinitely, set the loops to -1 or call the overloaded play function.
play(string)This is an overload of the play function which calls the first play function and sets the loops automatically to -1. Takes in a string for the name of the song to be played.

Example:

-- Play the title music
Music.play("title", -1) -- play the title music and loop continuously.

top


stop

FunctionDescription
stop()Stops the currently playing music. Only one song can play at a time, so no string is needed for the music name.

Example:

-- Stop the music
Music.stop()

top


pause

FunctionDescription
pause()Pauses the currently playing music. Only one song can play at a time, so no string is needed for the music name.

Example:

-- Pause the music
Music.pause()

top


resume

FunctionDescription
resume()Resume the currently paused music from the position where it was paused.

Example:

-- Resume the music
Music.resume()

top


set_volume

FunctionDescription
set_volume(int)Sets the volume of the music player. Takes in an int value between [0 - 100].

Example:

-- Set the volume to 50%
Music.set_volume(50)

top


is_playing

FunctionDescription
is_playing()Checks to see if the music channel is currently playing. Returns true if the music is playing, false otherwise.

Example:

-- Check if the music player is playing.
if Music.is_playing() then 
	Music.set_volume(50)
end

top


Sound Player

The sound player is used when we want small chunk soundFx played. The Sound Player, like the Music Player will only play sounds that have already been loaded into the Asset Manager. However, unlike the music player, the user must specify the channel that we want the music to be played on.

If the user chooses -1 for the channel, the sound FX will be played on any open channel. There there are no open channels, the Sound Player will log an error.

  • Valid sound fx file formats:
    • MP3
    • WAV

Functions:

play

FunctionDescription
play(string, int, int)The play function takes in a string for the soundFx name to be played and an int value for the number of loops and another int for the channel to play the sound on.
play(string)This is an overload of the play function which calls the first play function and sets the loops automatically to 0, to only loop once, and sets the channel to -1, so it will play on any open channel. Takes in a string for the name of the soundFx to be played.

Example:

-- Play the sword_slash soundFX
Sound.play("sword_slash", 0, -1) -- Don't loop and play on any open channel.
Sound.play("sword_slash")	-- Same as above; however, uses the default values.

top


stop

FunctionDescription
stop(int)stop function takes in an int for the channel that we want to stop playing. -1 will stop all channels.

Example:

-- Stop channel 5
Sound.stop(5)

top


set_volume

FunctionDescription
set_volume(int, int)Sets the volume of the specified channel. The first value is the channel, the second value is the volume [0 - 100]. If the channel is -1, it will set the volume to all channels to the specified volume.

Example:

-- Set the volume off all channels to 50%
Sound.set_volume(-1, 50)

top