游戏设置的音效音乐及其他要点


-- 音效滑动条
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 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值