cocos2d-x stopEffect使用

I just added a stopEffect method yesterday. You need to use the ALuint that is returned by playEffect. Also you can do looping without modifying SimpleAudioEngine. You create a CDSourceWrapper object and set the sourceId to the value returned by playEffect, then you can toggle looping on/off as well as adjusting pitch, gain and panning.

There is no correspondence between sounds and OpenAL sources, the sources are dynamically reallocated based on play requests. This is how CocosDenshion can play multiple instances of the same sound. Therefore you must store the source id returned when you call play effect. However, the way SimpleAudioEngine is set up with a single channel group you need to realise that the source id may be reused which could be an issue with looping sounds. If you want to do looping you should probably be looking at CDAudioManager and allocating the looped sounds to their own channel group.


cocos2d-x 中使用的是SimpleAudioEngine,对于里面的stopEffect方法,参数是一个ALuint,这个参数是方法playEffect的返回值,所以当我们试图控制一个循环音效的暂停或者继续时,要使用这个返回值ALuint,因为可能同时会有多个循环音效,所以具体的做法就是在外面建立playeEffect方法返回值的一个对应表,我这边使用map<SoundIndex ,unsigned int>进行存储。
需要主要的一点是对与map的存储操作,不能使用insert方法,因为对于map中已存在的索引数据再次调用insert方法时,并不更新map数据,而同时playEffect方法每次都会有不同的返回的值,所以要使用map的数组存储方式,比如
map[1]= 2

这样就达到了多次播放同一个音效时,能及时更新map数据,stopEffect的效果

参考:http://www.cocos2d-iphone.org/forum/topic/1254

你可能感兴趣的:(cocos2d-x)