Add CocosDenshion to Cocos2d-x

Source: Internet
Author: User

Sound is one of the important elements in the game, and a good music can add a lot of color to the game. The Cocos2d-x engine provides strong sound support, and today we'll come together to learn how to use these interfaces to add background and special effects music in the game. 1. Supported music file formats on different platforms:
// android effect only support ogg#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)    #define EFFECT_FILE        "effect2.ogg"#elif( CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)    #define EFFECT_FILE        "effect1.raw"#else    #define EFFECT_FILE        "effect1.wav"#endif // CC_PLATFORM_ANDROID#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)    #define MUSIC_FILE        "music.mid"#elif (CC_TARGET_PLATFORM == CC_PLATFORM_BLACKBERRY || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX )    #define MUSIC_FILE        "background.ogg"#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)    #define MUSIC_FILE        "background.wav"#else    #define MUSIC_FILE        "background.mp3"#endif // CC_PLATFORM_WIN32
2. Pre-load the sound file
// preload background music and effectSimpleAudioEngine::sharedEngine()->preloadBackgroundMusic( MUSIC_FILE );SimpleAudioEngine::sharedEngine()->preloadEffect( EFFECT_FILE );    // set default volumeSimpleAudioEngine::sharedEngine()->setEffectsVolume(0.5);SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.5);
3. Some common operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.