• 播放背景音乐
    • 播放音效

    播放背景音乐

    通过下面的方式,播放一个音频文件作为背景音乐,可以控制背景音乐是否循环播放。

    C++

    1. #include "SimpleAudioEngine.h"
    2. using namespace CocosDenshion;
    3. auto audio = SimpleAudioEngine::getInstance();
    4. // set the background music and continuously play it.
    5. audio->playBackgroundMusic("mymusic.mp3", true);
    6. // set the background music and play it just once.
    7. audio->playBackgroundMusic("mymusic.mp3", false);

    播放音效

    通过下面的方式,将一个音频文件作为音效。

    C++

    1. #include "SimpleAudioEngine.h"
    2. using namespace CocosDenshion;
    3. auto audio = SimpleAudioEngine::getInstance();
    4. // play a sound effect, just once.
    5. audio->playEffect("myEffect.mp3", false, 1.0f, 1.0f, 1.0f);

    原文: http://docs.cocos.com/cocos2d-x/manual/zh/audio/playing.html