axmol/cocos/scripting/lua-bindings/script/AudioEngine.lua

121 lines
2.8 KiB
Lua
Raw Normal View History

2014-03-10 14:04:58 +08:00
--Encapsulate SimpleAudioEngine to AudioEngine,Play music and sound effects.
local M = {}
function M.stopAllEffects()
cc.SimpleAudioEngine:getInstance():stopAllEffects()
2014-03-10 14:04:58 +08:00
end
function M.getMusicVolume()
return cc.SimpleAudioEngine:getInstance():getMusicVolume()
2014-03-10 14:04:58 +08:00
end
function M.isMusicPlaying()
return cc.SimpleAudioEngine:getInstance():isMusicPlaying()
2014-03-10 14:04:58 +08:00
end
function M.getEffectsVolume()
return cc.SimpleAudioEngine:getInstance():getEffectsVolume()
2014-03-10 14:04:58 +08:00
end
function M.setMusicVolume(volume)
cc.SimpleAudioEngine:getInstance():setMusicVolume(volume)
2014-03-10 14:04:58 +08:00
end
function M.stopEffect(handle)
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
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
cc.SimpleAudioEngine:getInstance():playMusic(filename, loopValue)
2014-03-10 14:04:58 +08:00
end
function M.pauseAllEffects()
cc.SimpleAudioEngine:getInstance():pauseAllEffects()
2014-03-10 14:04:58 +08:00
end
function M.preloadMusic(filename)
cc.SimpleAudioEngine:getInstance():preloadMusic(filename)
2014-03-10 14:04:58 +08:00
end
function M.resumeMusic()
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
return cc.SimpleAudioEngine:getInstance():playEffect(filename, loopValue)
2014-03-10 14:04:58 +08:00
end
function M.rewindMusic()
cc.SimpleAudioEngine:getInstance():rewindMusic()
2014-03-10 14:04:58 +08:00
end
function M.willPlayMusic()
return cc.SimpleAudioEngine:getInstance():willPlayMusic()
2014-03-10 14:04:58 +08:00
end
function M.unloadEffect(filename)
cc.SimpleAudioEngine:getInstance():unloadEffect(filename)
2014-03-10 14:04:58 +08:00
end
function M.preloadEffect(filename)
cc.SimpleAudioEngine:getInstance():preloadEffect(filename)
2014-03-10 14:04:58 +08:00
end
function M.setEffectsVolume(volume)
cc.SimpleAudioEngine:getInstance():setEffectsVolume(volume)
2014-03-10 14:04:58 +08:00
end
function M.pauseEffect(handle)
cc.SimpleAudioEngine:getInstance():pauseEffect(handle)
2014-03-10 14:04:58 +08:00
end
function M.resumeAllEffects(handle)
cc.SimpleAudioEngine:getInstance():resumeAllEffects()
2014-03-10 14:04:58 +08:00
end
function M.pauseMusic()
cc.SimpleAudioEngine:getInstance():pauseMusic()
2014-03-10 14:04:58 +08:00
end
function M.resumeEffect(handle)
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