LÖVE has no IDE, and Atom is a code editor - there is no drag and dropping files. As such, everything you really ever want to accomplish needs to be done through code. Loading graphics? Code. Loading Audio? Code. Any other data you might want to load? Yep, code.
So, in a simple case you'll write a line of code for every piece of sfx or music you might want to load:
Code: Select all
-- inside love.load, or any other place you might want
-- this assumes that the files are placed right next to main.lua, in the same folder
local sfx1 = love.audio.newSource( "sfx1.ogg", "static" )
local sfx2 = love.audio.newSource( "sfx2.ogg", "static" )
local bgm1 = love.audio.newSource ( "bgm1.ogg", "stream" )
-- etc
(the "static" defines that the audio file is decoded into memory at once, which is fine for sfx. For longer audio tracks like music, the "stream" option is generally recommended)
However, if you have a bunch of files, you can also write a simple for loop to enumerate through a folder's contents. Like, lets assume you create a folder named "sfx" next to your main.lua, you could use the following snippet:
Code: Select all
local files = love.filesystem.getDirectoryItems( "sfx" ) -- grabs and returns a table of files and subdirectories as strings
local sfx = {}
for i = 1, #files do
sfx[files[i]] = love.audio.newSource ( "sfx/" .. files[i], "static" )
end
This then gives you a table that contains all your sound effects in the said sfx folder. After that loading has been done, you can play individual sound effects like:
Code: Select all
love.audio.play ( sfx["jump.ogg"] ) -- assuming there is a file named "jump.ogg" among the files we loaded earlier
You may want to trim the file extension from the file name as you save them into the sfx table, but I'll leave that up to you.