Reputation: 1173
I'm making a game in Cocos2D iOS and would like play a short audio clip (in .m4a format) when the launch image (Default) is displayed.
I tried adding this line:
[[OALSimpleAudio sharedInstance] playBg:@"clip.m4a"];
in application didFinishLaunchingWithOptions
but doesn't work.
I also tried playing a .caf file instead of .m4a, but it also doesn't play.
Can you guys please help me in this regard?
Thanks a lot!
Upvotes: 0
Views: 276
Reputation: 575
Are you talking about the default loading screen that is defined in your project settings as 'default.png'? If yes, I don't think it's possible to play a sound at the same moment the app is launched, because it is currently loading it. What you could do however is a IntroScene that would only implement the onEnter
method and immediately apply a transition to, example, your Main Menu. This is what I am doing right now in my game (using cocos2D 2.1, but I guess this isn't very different from a version to another) :
-(void) onEnter
{
[super onEnter];
CCScene *scene;
//Check if app has already launched once
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"]) {
scene = [MainMenuScene sceneWithParticles:nil];
}else{
scene = [Tutorial sceneWithParticle:nil];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
//PLAY YOUR SOUND HERE
//Transition
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:scene]];
}
Hope this helps! :)
Upvotes: 1