-1

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"]];
  • 1
    "doesn't seem to work" is not a problem description. Describe what is happening and what makes you think it only "seems" not to work (does it or does it not?). Did you verify that the code runs? – CodeSmile Aug 19 '14 at 20:16
  • #LearnCocos2D I edited my question. –  Aug 19 '14 at 21:08
  • 1
    But the cocos2d part before the interstitial works fine? Do you do anything to stop CCDirector or deallocate its view? Check if [CCDirector sharedDirector].view is still a valid reference and CCDirector running its visit method frequently. – CodeSmile Aug 19 '14 at 21:20
  • #LearnCocos2D Yes,it works fine. I use this line [[CCDirector sharedDirector] pause]; when game over window appears, but I always resume game in didLoad. I tried to remove that line - there is just no difference. I don't deallocate it. I don't know how to check both, but I tried to guess what you mean(in the edited question) –  Aug 19 '14 at 22:03

1 Answers1

0

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"]];
    }];