@ adam.artajew के उत्तर के लिए धन्यवाद! मैंने इसे Cocos2D v3
के साथ उपयोग करने के लिए संशोधित किया और गेम इंजन में किसी भी स्थान से इसका उपयोग करने के लिए ऑडियो इंजन पर Crossfade
श्रेणी बनाई। अब यह करता है निम्न क्रियाएँ:
- फीका बाहर
- ट्रैक बदलें
- फीका
OALSimpleAudio+Crossfade.m
में इन आयात में शामिल हैं:
#import "CCDirector_Private.h"
#import "CCActionManager.h"
और विधि को लागू:
- (void)playBg:(NSString *)name crossfade:(BOOL)crossfade {
// Skip if already playing requested track
if (self.bgPlaying &&
[self.backgroundTrack.currentlyLoadedUrl.lastPathComponent isEqualToString:name]) {
return;
}
// Play right now if no crossfade needed
if (!crossfade) {
[self playBg:name loop:true];
}
// Fade out just if music's playing right now
NSMutableArray *actions = [NSMutableArray array];
if (self.bgPlaying) {
id fadeOut = [CCActionTween actionWithDuration:0.5 key:@"bgVolume" from:self.bgVolume to:0.0f];
[actions addObject:fadeOut];
}
// Replace current track with fade in effect
id playNew = [CCActionCallBlock actionWithBlock:^{
[self playBg:name loop:true];
}];
id fadeIn = [CCActionTween actionWithDuration:0.5 key:@"bgVolume" from:0.0f to:1.0f];
// Combime final action
[actions addObjectsFromArray:@[playNew, fadeIn]];
id sequence = [CCActionSequence actionWithArray:actions.copy];
// Run action
[[[CCDirector sharedDirector] actionManager] addAction:sequence target:self paused:NO];
}
उपयोग:OALSimpleAudio+Crossfade.h
को शामिल करें और फोन
[[OALSimpleAudio sharedInstance] playBg:@"MainBgMusic.mp3" crossfade:YES];
ठीक है, धन्यवाद। –