2013-11-03 7 views
6

मैं SpriteKit उपयोग करने के लिए ध्वनि खेलना चाहते हैं, सवाल यह है कि मैं समारोह का उपयोग करें ।ध्वनि को थामने के लिए जब उपयोग SpriteKit

कैसे ध्वनि को रोकने के लिए जब skview.pauseYES पर सेट किया जाता है, और जब skview.pauseNO पर सेट है ध्वनि को फिर से शुरू करने के लिए?

+0

यदि मैं गलत आप, ध्वनि प्रभाव खेल रहे हैं ... कम 1 या 2 सेकंड के लिए कुछ playSoundFileNamed विधि का उपयोग करना चाहिए विस्फोट की तरह ध्वनि – lionserdar

+0

नहीं कर रहा हूँ और यह भी मुझे लगता है कि यह होगा बेहतर होगा यदि आप पृष्ठभूमि संगीत के लिए AVAudioPlayer का उपयोग करते हैं, तो raywenderlich.com (http://www.raywenderlich.com/49625/sprite-kit-tutorial-tutorial-space-shooter) पर इस ट्यूटोरियल की जांच करें ध्वनि अनुभाग – lionserdar

+0

देखें आप एक का उपयोग भी कर सकते हैं ऑब्जेक्टल – LearnCocos2D

उत्तर

9

यह कुछ समय रहा है, लेकिन AVAudio का उपयोग करके आप क्या कर सकते हैं इसका आधार यहां है। मैं इस उदाहरण में पृष्ठभूमि संगीत का उपयोग करूंगा लेकिन यह किसी भी तरह से किया जा सकता है। आप इसे SKSpriteNode के उप-वर्ग में एक कस्टम ध्वनि रखने के लिए रख सकते हैं जिसे स्वयं या दूसरों द्वारा रोक दिया जा सकता है।

//Add this to your imports: 
#import <AVFoundation/AVFoundation.h>; 

//Add the following variable in your interface. 
AVAudioPlayer *player; 

// Put this in an init or something of the like. 
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"musicFileSound" ofType:@"wav"]]; 
_player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; 

तब उपयोग [_player play];

उपयोग [_player pause] को रोकने के लिए शुरू करने के लिए।

और [_player stop]

Here is the documentation for it, there are some cool things you can do with it.

संबंधित मुद्दे