Sounds and sounds in Cocos2d-X

Source: Internet
Author: User

Sounds and sounds in Cocos2d-X

There will be a variety of game sound when playing the game, such as starting the game there will be background sound, victory or failure there will be some sound, In the Cocos2d-X can use CocosDenshion for a variety of sounds

Before using CocosDenshion, you must add a header file and a namespace in the program.

#include "SimpleAudioEngine.h"using namespace CocosDenshion;


Then, add the music file to the Resource folder under the project directory.


Play background music

// Play background music // The first parameter: music file name // The second parameter: whether to play CocosDenshion cyclically: SimpleAudioEngine: sharedEngine ()-> playBackgroundMusic ("OnLand.wma ", true );


Stop playing background music

// Stop playing background music SimpleAudioEngine: sharedEngine ()-> stopBackgroundMusic ();


Playing Sound Effects

// Play sound effect // parameter: music file name // return value: audio number unsigned int effectID = CocosDenshion: SimpleAudioEngine: sharedEngine ()-> playEffect ("EatCoin.wma ");


Stop playing sound effects

// CocosDenshion: SimpleAudioEngine: sharedEngine ()-> stopEffect (effectID );


Set the volume of background music

// Set the volume of the background music. // The volume range is 0 ~ 1 CocosDenshion: SimpleAudioEngine: sharedEngine ()-> setBackgroundMusicVolume (. 5f );

Set the sound volume

// Set the sound volume. // The volume range is 0 ~ 1 CocosDenshion: SimpleAudioEngine: sharedEngine ()-> setjavastsvolume (. 5f );


Cache background music

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


Accelerated cache sound effects

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



Zookeeper

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.