zoukankan      html  css  js  c++  java
  • Cocos2d-X中的声音和音效

    在玩游戏时都会有各种游戏音,如启动游戏时会有背景音,胜利或者失败会有一些音效。在Cocos2d-X中能够使用CocosDenshion实现各种声音

    在使用CocosDenshion之前须要在程序中加入一个头文件和一个命名空间

    #include "SimpleAudioEngine.h"
    using namespace CocosDenshion;


    然后在project文件夹下的Resource文件夹中加入音乐文件


    播放背景音乐

    //播放背景音乐
        //第一个參数:音乐文件名称
        //第二个參数:是否循环播放
         CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("OnLand.wma", true);
    


    停止播放背景音乐

    //停止播放背景音乐
        SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();


    播放音效

    //播放音效
        //參数:音乐文件名称
        //返回值:音效的编号
        unsigned int effectID =  CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("EatCoin.wma");
    


    停止播放音效

     //停止播放编号为effectID的音效
        CocosDenshion::SimpleAudioEngine::sharedEngine()->stopEffect(effectID); 
    


    设置背景音乐的音量

    //设置背景音乐的音量
        //音量的范围:0~1
        CocosDenshion::SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(.5f);
    

    设置音效的音量

    //设置音效的音量
        //音量的范围:0~1
        CocosDenshion::SimpleAudioEngine::sharedEngine()->setEffectsVolume(.5f);
    


    加速缓存背景音乐

    CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("OnLand.wma");


    加速缓存音效

    CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("EatCoin.wma");
    



    

  • 相关阅读:
    记录一次线上优化流程
    php ignite 使用问题记录
    invalid contrller specified 错误分析及解决
    koa 2 的 async 和 await 语法
    koa 2 的安装
    vue 自定义组件 v-model双向绑定、 父子组件同步通信的多种写法
    VS2019专业版和企业版激活密钥
    RE:ゼロから始める PKU 生活 episode 2
    CSP-S 2020 游记
    ioi2021集训队作业
  • 原文地址:https://www.cnblogs.com/brucemengbm/p/7375526.html
Copyright © 2011-2022 走看看