background music
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
background music
im making a game and i need to have some looping background music but i cant figure out the code can someone help me?
Re: background music
Welcome to LÖVE!
To get some music playing you have to create a Source with love.sound.newSource. This will load the encoded audio file and prepare it for playback. Set it to looping with Source:setLooping and then call Source:play to start playback. Use Source:setVolume to control its volume so it really is background music.
Putting it all together:
We recommend you use the Vorbis audio format. WAVE and mp3 may show some issues.
To get some music playing you have to create a Source with love.sound.newSource. This will load the encoded audio file and prepare it for playback. Set it to looping with Source:setLooping and then call Source:play to start playback. Use Source:setVolume to control its volume so it really is background music.
Putting it all together:
Code: Select all
function love.load()
-- Loading the audio file.
Music = love.audio.newSource("rsar.ogg")
-- Letting it loop forever.
Music:setLooping(true)
-- Making it a bit quieter.
Music:setVolume(0.5)
-- Starting playback.
Music:play()
end
function love.keypressed(key)
if key == "escape" then
-- Exit on escape.
love.event.quit()
elseif key == " " then
-- Play or stop on spacebar.
if Music:isStopped() then
Music:play()
else
Music:stop()
end
end
end
Shallow indentations.
Re: background music
thanks mate you have helped me alot
Who is online
Users browsing this forum: Google [Bot] and 211 guests