2011-12-28 43 views

回答

1

在場景中使用

self.isTouchEnabled = YES; 

現在你可以像ccTouchBegin或ccTouchEnd方法應對(忘了他們的名字)。所以當觸摸開始的時候,你可以安排一種能夠反覆播放效果器的方法。當觸摸結束時,取消調度。

1

如果您使用SimpleAudioEngine,則可以在調用ccTouchesBegan:withEvent時使用playBackgroundMusic :(默認爲循環),然後在調用ccTouchesEnd:withEvent:時調用stopBackgroundMusic :.

要使用SimpleAudioEngine:

#import "SimpleAudioEngine.h" 

要ccTouchesBegan播放音樂: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"]; 

要停止音樂ccTouchesEnd:withEvent:方法

[[SimpleAudioEngine sharedEngine] stopBackgroundMusic];