sounds.lua 435 B

1234567891011121314151617181920212223
  1. local Sounds = {
  2. sources = {}
  3. }
  4. function Sounds:load()
  5. local files = love.filesystem.getDirectoryItems( "sounds" )
  6. for k, f in pairs( files ) do
  7. if f:match( ".wav$" ) then
  8. local name = f:match( "(.*).wav" )
  9. local s = love.audio.newSource( "sounds/" .. f, "static" )
  10. Sounds.sources[name] = s
  11. end
  12. end
  13. end
  14. function Sounds:play( name )
  15. if Sounds.sources[name] then
  16. Sounds.sources[name]:play()
  17. end
  18. end
  19. return Sounds