Difference between revisions of "Source:setVolume"
(Added examples) |
|||
Line 9: | Line 9: | ||
=== Returns === | === Returns === | ||
Nothing. | Nothing. | ||
+ | == Examples == | ||
+ | Make a sound quieter or completely silent. | ||
+ | <source lang="lua"> | ||
+ | function love.load() | ||
+ | sound = love.audio.newSource("sound.wav") | ||
+ | |||
+ | sound:setVolume(0.5) -- 50% volume | ||
+ | sound:setVolume(0) -- No sound | ||
+ | end | ||
+ | </source> | ||
+ | Set different volumes depending on the sound type. | ||
+ | <source lang="lua"> | ||
+ | function love.load() | ||
+ | effect = love.audio.newSource("soundeffect.wav") | ||
+ | music = love.audio.newSource("music.mp3") | ||
+ | |||
+ | masterVolume = 0.5 -- Maximum volume for all sounds | ||
+ | effectVolume = 0.75 | ||
+ | musicVolume = 1 | ||
+ | |||
+ | effect:setVolume(masterVolume * effectVolume) | ||
+ | music:setVolume(masterVolume * musicVolume) | ||
+ | end | ||
+ | </source> | ||
== See Also == | == See Also == | ||
* [[parent::Source]] | * [[parent::Source]] |
Revision as of 16:10, 3 November 2016
Sets the current volume of the Source.
Function
Synopsis
Source:setVolume( volume )
Arguments
number volume
- The volume for a Source, where 1.0 is normal volume. Volume cannot be raised above 1.0.
Returns
Nothing.
Examples
Make a sound quieter or completely silent.
function love.load()
sound = love.audio.newSource("sound.wav")
sound:setVolume(0.5) -- 50% volume
sound:setVolume(0) -- No sound
end
Set different volumes depending on the sound type.
function love.load()
effect = love.audio.newSource("soundeffect.wav")
music = love.audio.newSource("music.mp3")
masterVolume = 0.5 -- Maximum volume for all sounds
effectVolume = 0.75
musicVolume = 1
effect:setVolume(masterVolume * effectVolume)
music:setVolume(masterVolume * musicVolume)
end
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info