1)I made a game using cocos2d-iphone v3.
2)I integrated a fullscreen advertisement.
3)I want to load a cocos2d scene, when user closes ad, but it doesn't work(I imported cocos2d framework).There is just a black screen after advertisement disappears with animation. "interstitialAdDidFINISH" appears in the output, so most likely, that last line is wrong.
-(void)interstitialAdActionDidFinish:(ADInterstitialAd *)interstitialAd {
interstitial = nil;
// [interstitialAd release];
// [ADInterstitialAd release];
requestingAd = NO;
NSLog(@"interstitialAdDidFINISH");
[[CCDirector sharedDirector] replaceScene:[CCBReader loadAsScene:@"MainScene"]];
}
I guess, that I can't load a cocos2d scene from UIViewController class so easy..... How can I do this?
EDIT: So ? It's not nil
if ( [CCDirector sharedDirector].view != nil) {
NSLog(@"Hey there");
}
EDIT 2: I found out, that [CCDirector sharedDirector]];
is a ViewController too.
I tried something like this . The game crashes, after iAd finished.
[self addChildViewController:[CCDirector sharedDirector]];
[self presentModalViewController:[CCDirector sharedDirector] animated:NO];
[[CCDirector sharedDirector] replaceScene:[CCBReader loadAsScene:@"MainScene"]];
I'v found solution. May be helpfull for others.
First, that's, how I present iad view controller from the MainScene
*ViewControllerAdEx= [[ ViewControllerAd alloc] init]; // making an instance of iad class
[[CCDirector sharedDirector] presentModalViewController:ViewControllerAdEx animated:YES];
[ViewControllerAdEx showFullScreenAd]; // caling a method from class
In the iad class, when iad finishes work:
[self dismissViewControllerAnimated:YES completion:^{
[[CCDirector sharedDirector] replaceScene:[CCBReader loadAsScene:@"MainScene"]];
}];