Cocos2d iphone cocos2d-如何仅在用户触摸时播放音效?

Cocos2d iphone cocos2d-如何仅在用户触摸时播放音效?,cocos2d-iphone,simpleaudioengine,Cocos2d Iphone,Simpleaudioengine,如何仅在用户触摸时播放音效?只要重复并在用户结束触摸时停止即可 谢谢。在您的场景中使用 self.isTouchEnabled = YES; 现在您可以响应ccTouchBegin或ccTouchEnd等方法(忘记它们的名称)。所以,是的,当触摸开始时,你可以安排一种方法,反复播放声音效果。当触摸结束时,取消计划。如果您使用SimpleAudioEngine,您可以在调用CCToucheSBegind:withEvent:时使用playBackgroundMusic:(默认为循环),然后在调用

如何仅在用户触摸时播放音效?只要重复并在用户结束触摸时停止即可

谢谢。

在您的场景中使用

self.isTouchEnabled = YES;

现在您可以响应ccTouchBegin或ccTouchEnd等方法(忘记它们的名称)。所以,是的,当触摸开始时,你可以安排一种方法,反复播放声音效果。当触摸结束时,取消计划。

如果您使用SimpleAudioEngine,您可以在调用CCToucheSBegind:withEvent:时使用playBackgroundMusic:(默认为循环),然后在调用ccTouchesEnd:withEvent:时调用stopBackgroundMusic:

要使用SimpleAudioEngine,请执行以下操作:

#import "SimpleAudioEngine.h"
要在CCTouches中播放音乐,请开始:withEvent:

SimpleAudioEngine *sae = [SimpleAudioEngine sharedEngine];
[sae preloadBackgroundMusic:@"MusicLoop.mp3"];
sae.backgroundMusicVolume = 0.5f;    // Sets the volume to 50%; this is optional
[sae playBackgroundMusic:@"MusicLoop.mp3"];
[[SimpleAudioEngine sharedEngine] stopBackgroundMusic];
要停止ccTouchesEnd:withEvent中的音乐,请执行以下操作:

SimpleAudioEngine *sae = [SimpleAudioEngine sharedEngine];
[sae preloadBackgroundMusic:@"MusicLoop.mp3"];
sae.backgroundMusicVolume = 0.5f;    // Sets the volume to 50%; this is optional
[sae playBackgroundMusic:@"MusicLoop.mp3"];
[[SimpleAudioEngine sharedEngine] stopBackgroundMusic];