zoukankan      html  css  js  c++  java
  • 【Cocos2DX 】初窥门径(9)播放音乐/音效

    Cocos2D对音乐/音效播放的封装已经很好了,下边是例子:

    定义2个文件:

    #define MUSIC_FILE        "LOLBgMusic.mp3"
    #define EFFECT_FILE		 "Attack.wav"


    在初始化的时候预加载音乐/音效文件:

    //预加载
    	CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(MUSIC_FILE);
    	CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect( EFFECT_FILE );
    	//设置音量
    	CocosDenshion::SimpleAudioEngine::sharedEngine()->setEffectsVolume(0.5);
    	CocosDenshion::SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.5);


    播放:

    		//循环播放背景音乐,
    		CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic(MUSIC_FILE,true);
    		//播放音效
    		CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(EFFECT_FILE);


    其他相关函数:

    // stop background music
    SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();
     // pause background music
     SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
    // resume background music
    SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
    // rewind background music
    SimpleAudioEngine::sharedEngine()->rewindBackgroundMusic();
    // is background music playing
    SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying()
    // add bakcground music volume
    SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume() + 0.1f);
    
    
    SimpleAudioEngine::sharedEngine()->pauseEffect(m_nSoundId);
    SimpleAudioEngine::sharedEngine()->resumeEffect(m_nSoundId);
    SimpleAudioEngine::sharedEngine()->pauseAllEffects();
    SimpleAudioEngine::sharedEngine()->resumeAllEffects();
    SimpleAudioEngine::sharedEngine()->stopAllEffects();





    转载请注明出处: http://blog.csdn.net/Vestigge





  • 相关阅读:
    HDU 4358 莫队算法+dfs序+离散化
    HDU 5692 线段树+dfs序
    Codeforces Round #377 (Div. 2) A B C D 水/贪心/贪心/二分
    LVS负载均衡的三种模式和八种算法总结
    hdfs 常用命令
    Linux 系统监控
    CentOS 7 时区设置
    kubernetes 留言版DEMO
    CentOS7 PostgreSQL 主从配置( 三)
    Postgres数据库在Linux中优化
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3022952.html
Copyright © 2011-2022 走看看