chore: make SFX a soundObject too
This commit is contained in:
parent
fed8ab4662
commit
3b1097c917
3 changed files with 45 additions and 7 deletions
|
@ -36,6 +36,8 @@ local Tileset = require(cwd .. "tileset")
|
||||||
local Autotile = require(cwd .. "autotile")
|
local Autotile = require(cwd .. "autotile")
|
||||||
local Background = require(cwd .. "background")
|
local Background = require(cwd .. "background")
|
||||||
|
|
||||||
|
local SFX = require(cwd .. "sfx")
|
||||||
|
|
||||||
-- INIT FUNCTIONS
|
-- INIT FUNCTIONS
|
||||||
-- Initilizing and configuring option
|
-- Initilizing and configuring option
|
||||||
|
|
||||||
|
@ -151,7 +153,7 @@ function Assets:addSFX(name, filepath)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Assets:newSFX(name, filepath)
|
function Assets:newSFX(name, filepath)
|
||||||
self.sfx[name] = love.audio.newSource( filepath, "static" )
|
self.sfx[name] = SFX(filepath)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Assets:clearSFX()
|
function Assets:clearSFX()
|
||||||
|
@ -161,9 +163,7 @@ end
|
||||||
|
|
||||||
function Assets:playSFX(filename)
|
function Assets:playSFX(filename)
|
||||||
if not (self.sfx[filename] == nil) then
|
if not (self.sfx[filename] == nil) then
|
||||||
self.sfx[filename]:stop()
|
self.sfx[filename]:play()
|
||||||
self.sfx[filename]:setVolume(core.options.data.audio.sfx / 100)
|
|
||||||
love.audio.play( self.sfx[filename] )
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
40
birb/modules/assets/sfx.lua
Normal file
40
birb/modules/assets/sfx.lua
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
-- assets/sfx :: the sfx object, essentially used to be able to just have an sfx
|
||||||
|
|
||||||
|
--[[
|
||||||
|
Copyright © 2020 Kazhnuz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
]]
|
||||||
|
|
||||||
|
|
||||||
|
local SFX = Object:extend()
|
||||||
|
|
||||||
|
-- INIT FUNCTIONS
|
||||||
|
-- Initilizing and configuring option
|
||||||
|
|
||||||
|
function SFX:new(filepath)
|
||||||
|
self.sound = love.audio.newSource(filepath, "static")
|
||||||
|
end
|
||||||
|
|
||||||
|
function SFX:play()
|
||||||
|
self.sound:stop()
|
||||||
|
self.sound:setVolume(core.options.data.audio.sfx / 100)
|
||||||
|
love.audio.play(self.sound)
|
||||||
|
end
|
||||||
|
|
||||||
|
return SFX
|
|
@ -267,9 +267,7 @@ end
|
||||||
|
|
||||||
function Menu:playNavigationSound()
|
function Menu:playNavigationSound()
|
||||||
if self.sound.active == true then
|
if self.sound.active == true then
|
||||||
love.audio.stop( self.sound.asset )
|
self.sound.asset:play()
|
||||||
self.sound.asset:setVolume(core.options.data.audio.sfx / 100)
|
|
||||||
love.audio.play( self.sound.asset )
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue