-- 音效滑动条
local nEffectVolume = GetUserDataIntger(USER_DATA_INT_EFFECT_VOLUME);
local effectSlider = currNode:getChildByName("Slider_effect");
effectSlider:addEventListener(settingSliderCall);
effectSlider:setPercent(nEffectVolume ~= 0 and nEffectVolume or 100);
-- 音乐滑动条
local nMusicVolume = GetUserDataIntger(USER_DATA_INT_MUSIC_VOLUME);
local musicSlider = currNode:getChildByName("Slider_music");
musicSlider:addEventListener(settingSliderCall);
musicSlider:setPercent(nMusicVolume ~= 0 and nMusicVolume or 100);
进度条函数setPercent这里用到一个a and b or c
条件判断为a是否为真,如果为真,则为b,否则为c,等同于a?b:c;
引用: int SetUserDataIntger( lua_State* pArgs )
{
if (!Lua_Tool::IsInteger(pArgs,1))
return 0;
int nIndex = Lua_Tool::GetInteger(pArgs,1);
if (!Lua_Tool::IsInteger(pArgs,2))
return 0;
int nValue = Lua_Tool::GetInteger(pArgs,2);
UserDataManager::GetInstance().SetUserData(nIndex, nValue);
return 0;
}
int GetUserDataIntger( lua_State* pArgs )
{
if (!Lua_Tool::IsInteger(pArgs,1))
return 0;
int nIndex = Lua_Tool::GetInteger(pArgs,1);
int nRst = UserDataManager::GetInstance().GetUserDataIntger(nIndex);
Lua_Tool::PushInteger(pArgs,nRst);
return 1;
}
这里是对于音效与音乐滑动条的初始化设置
-- 设置界面的滑动条的滑动
function PopUpLayer:settingSliderTouchFuc(sender, eventType)
local SliderName = sender:getName();
if eventType == ccui.SliderEventType.percentChanged then
-- 滑动条移动
elseif eventType == ccui.SliderEventType.slideBallUp then
-- 滑动条滑动结束
if SliderName == "Slider_effect" then
-- 获取滑动值
local endPercend = sender:getPercent();
SetUserDataIntger(USER_DATA_INT_EFFECT_VOLUME,(endPercend ~= 0 and endPercend or -1));
-- 因为0表示第一次设置的默认值,所以要设为-1来区别
SetUserDataIntger(USER_DATA_INT_EFFECT_VOLUME2,(endPercend ~= 0 and endPercend or -1));
-- 记录音效按钮关闭前的音效百分比
-- 如果开关关闭&volume不为0 或者 开关打开&volume为0 需要开关动画
if self._CurrentNode then
local effectSwitchBtn = self._CurrentNode:getChildByName("Button_switch_1");
if effectSwitchBtn then
local tag = effectSwitchBtn:getTag();
if endPercend ~= 0 and tag == 0 or
endPercend == 0 and tag == 1 then
self:settingButtonAnimation(effectSwitchBtn, tag);
end
end
end
elseif SliderName == "Slider_music" then
-- 获取滑动值
local endPercend = sender:getPercent();
SetUserDataIntger(USER_DATA_INT_MUSIC_VOLUME,(endPercend ~= 0 and endPercend or -1));
-- 因为0表示第一次设置的默认值,所以要设为-1来区别
if gAudioID then
ccexp.AudioEngine:setVolume(gAudioID, endPercend / 100);
end
-- 如果开关关闭&volume不为0 或者 开关打开&volume为0 需要开关动画
if self._CurrentNode then
local musicSwitchBtn = self._CurrentNode:getChildByName("Button_switch_2");
if musicSwitchBtn then
local tag = musicSwitchBtn:getTag();
if endPercend ~= 0 and tag == 0 or
endPercend == 0 and tag == 1 then
end
end
end
end
-- 滑动条的获取结束
end
-- 滑动结束
end