2014-03-10 14:04:58 +08:00
|
|
|
--Encapsulate SimpleAudioEngine to AudioEngine,Play music and sound effects.
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
function M.stopAllEffects()
|
2014-04-17 10:36:08 +08:00
|
|
|
cc.SimpleAudioEngine:getInstance():stopAllEffects()
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.getMusicVolume()
|
2014-04-17 10:36:08 +08:00
|
|
|
return cc.SimpleAudioEngine:getInstance():getMusicVolume()
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.isMusicPlaying()
|
2014-04-17 10:36:08 +08:00
|
|
|
return cc.SimpleAudioEngine:getInstance():isMusicPlaying()
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.getEffectsVolume()
|
2014-04-17 10:36:08 +08:00
|
|
|
return cc.SimpleAudioEngine:getInstance():getEffectsVolume()
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.setMusicVolume(volume)
|
2014-04-17 10:36:08 +08:00
|
|
|
cc.SimpleAudioEngine:getInstance():setMusicVolume(volume)
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.stopEffect(handle)
|
2014-04-17 10:36:08 +08:00
|
|
|
cc.SimpleAudioEngine:getInstance():stopEffect(handle)
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.stopMusic(isReleaseData)
|
|
|
|
local releaseDataValue = false
|
|
|
|
if nil ~= isReleaseData then
|
|
|
|
releaseDataValue = isReleaseData
|
|
|
|
end
|
2014-04-17 10:36:08 +08:00
|
|
|
cc.SimpleAudioEngine:getInstance():stopMusic(releaseDataValue)
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.playMusic(filename, isLoop)
|
|
|
|
local loopValue = false
|
|
|
|
if nil ~= isLoop then
|
|
|
|
loopValue = isLoop
|
|
|
|
end
|
2014-04-17 10:36:08 +08:00
|
|
|
cc.SimpleAudioEngine:getInstance():playMusic(filename, loopValue)
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.pauseAllEffects()
|
2014-04-17 10:36:08 +08:00
|
|
|
cc.SimpleAudioEngine:getInstance():pauseAllEffects()
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.preloadMusic(filename)
|
2014-04-17 10:36:08 +08:00
|
|
|
cc.SimpleAudioEngine:getInstance():preloadMusic(filename)
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.resumeMusic()
|
2014-04-17 10:36:08 +08:00
|
|
|
cc.SimpleAudioEngine:getInstance():resumeMusic()
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.playEffect(filename, isLoop)
|
|
|
|
local loopValue = false
|
|
|
|
if nil ~= isLoop then
|
|
|
|
loopValue = isLoop
|
|
|
|
end
|
2014-04-17 10:36:08 +08:00
|
|
|
return cc.SimpleAudioEngine:getInstance():playEffect(filename, loopValue)
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.rewindMusic()
|
2014-04-17 10:36:08 +08:00
|
|
|
cc.SimpleAudioEngine:getInstance():rewindMusic()
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.willPlayMusic()
|
2014-04-17 10:36:08 +08:00
|
|
|
return cc.SimpleAudioEngine:getInstance():willPlayMusic()
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.unloadEffect(filename)
|
2014-04-17 10:36:08 +08:00
|
|
|
cc.SimpleAudioEngine:getInstance():unloadEffect(filename)
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.preloadEffect(filename)
|
2014-04-17 10:36:08 +08:00
|
|
|
cc.SimpleAudioEngine:getInstance():preloadEffect(filename)
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.setEffectsVolume(volume)
|
2014-04-17 10:36:08 +08:00
|
|
|
cc.SimpleAudioEngine:getInstance():setEffectsVolume(volume)
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.pauseEffect(handle)
|
2014-04-17 10:36:08 +08:00
|
|
|
cc.SimpleAudioEngine:getInstance():pauseEffect(handle)
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.resumeAllEffects(handle)
|
2014-04-17 10:36:08 +08:00
|
|
|
cc.SimpleAudioEngine:getInstance():resumeAllEffects()
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.pauseMusic()
|
2014-04-17 10:36:08 +08:00
|
|
|
cc.SimpleAudioEngine:getInstance():pauseMusic()
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function M.resumeEffect(handle)
|
2014-04-17 10:36:08 +08:00
|
|
|
cc.SimpleAudioEngine:getInstance():resumeEffect(handle)
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.getInstance()
|
|
|
|
return cc.SimpleAudioEngine:getInstance()
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.destroyInstance()
|
|
|
|
return cc.SimpleAudioEngine:destroyInstance()
|
2014-03-10 14:04:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
local modename = "AudioEngine"
|
|
|
|
local proxy = {}
|
|
|
|
local mt = {
|
|
|
|
__index = M,
|
|
|
|
__newindex = function (t ,k ,v)
|
|
|
|
print("attemp to update a read-only table")
|
|
|
|
end
|
|
|
|
}
|
|
|
|
setmetatable(proxy,mt)
|
|
|
|
_G[modename] = proxy
|
|
|
|
package.loaded[modename] = proxy
|
|
|
|
|
|
|
|
|