2011-08-28 17 views
6

इतनी खोज के बाद, मुझे cocos2d में प्रभाव रोकने के लिए कोई समाधान नहीं मिला।cocos2d में प्रभाव रोकें?

मेरी प्रभाव एक ध्वनि है कि डेटाबेस से लिया गया खेल रहा है, इसलिए उस विशिष्ट ध्वनि मैं यह करने के लिए किया है को रोकने के लिए:

[[SimpleAudioEngine sharedEngine] stopEffect:[NSString stringWithFormat:@"%@.wav",sound]]; 

लेकिन मैं चेतावनी मिल गया: stopEffect डाली बिना सूचक से पूर्णांक बनाने ..

वह क्यों है? मैं एक ही समय में चल रहे सभी ध्वनियों को कैसे रोक सकता हूं ??? या एक विशेष नहीं है? कोई अन्य तरीका ?

बहुत बहुत धन्यवाद।

+1

ठीक है मुझे यह मिला: ALUint soundEffectID; soundEffectID = [[SimpleAudioEngine साझाEngine] playEffect: play]; [[SimpleAudioEngine साझाEngine] stopEffect: soundEffectID]; – Curnelious

+0

आपको इसे एक उत्तर के रूप में सबमिट करना चाहिए और प्रश्न को हल करने के लिए अपना उत्तर स्वीकार करना चाहिए। –

उत्तर

20

ठीक आप ऐसा करते हैं:

ALuint soundEffectID; 

//to start 
soundEffectID=[[SimpleAudioEngine sharedEngine] playEffect:@"my sound"]; 
//to stop 
[[SimpleAudioEngine sharedEngine] stopEffect:soundEffectID]; 
8

आप 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 
0
कुछ अधिक

...

यदि आप चल रहे सभी ध्वनियां रोक चाहते हैं, तो

[SimpleAudioEngine end]; 

लेकिन यह भी इतना sharedEngine dealloc जाएगा यू "SharedEngine" कॉल करने के लिए मामले चाहता हूँ में की जरूरत है फिर से ध्वनि खेलें :)