经过这么多搜索,我找不到任何解决方案来停止cocos2d的效果.
我的效果是播放从数据库中获取的声音,所以为了阻止我必须这样的特定声音:
[[SimpleAudioEngine sharedEngine] stopEffect:[NSString stringWithFormat:@"%@.wav",sound]];
Run Code Online (Sandbox Code Playgroud)
但是我收到了警告:stopEffect从指针生成整数而没有强制转换..
这是为什么 ?我怎么能停止一次播放的所有声音?或不是一个特定的?任何其他方式?
非常感谢 .
小智 20
好的,你这样做:
ALuint soundEffectID;
//to start
soundEffectID=[[SimpleAudioEngine sharedEngine] playEffect:@"my sound"];
//to stop
[[SimpleAudioEngine sharedEngine] stopEffect:soundEffectID];
Run Code Online (Sandbox Code Playgroud)
如果你没有soundEffectID,你可以做下一步.它帮助我解决了我的问题.
static NSMutableArray *soundsIdArr;
@implementation MusicAndSound
//It must be run before using sound
+(void)initSound
{
NSLog(@"initSound");
soundsIdArr = [NSMutableArray arrayWithCapacity:0];
[soundsIdArr retain];
}
+(void)playSound:(NSString *)fileName
{
[[SimpleAudioEngine sharedEngine] setEffectsVolume:1.0];
soundEffectID = [[SimpleAudioEngine sharedEngine] playEffect:[[NSBundle mainBundle] pathForResource:fileName ofType:nil]];
[soundsIdArr addObject:[NSString stringWithFormat:@"%i", soundEffectID]];
}
+(void)stopAllSounds
{
[[SimpleAudioEngine sharedEngine] setEffectsVolume:0.0];
for (int i=0; i<[soundsIdArr count]; i++)
{
[[SimpleAudioEngine sharedEngine] stopEffect:[[soundsIdArr objectAtIndex:i] intValue]];
}
[soundsIdArr removeAllObjects];
}
- (void)dealloc
{
[soundsIdArr release];
[super dealloc];
}
@end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5899 次 |
| 最近记录: |