0

I have a HUD layer containing an iAd with a function that moves the ad offscreen. I use this code to add the HUD layer to one of the scenes I have:

CCScene *scene = [CCScene node];

hudLayer *hud = [hudLayer node];
[scene addChild:hud z:1 tag:5];

MainMenuView *layer = [[[MainMenuView alloc] initWithHud:hud] autorelease];
[scene addChild:layer];

return scene;

hudLayer is the iAd class file name.

Now when I go to another scene the HUD layer is still there even if I added it in another scene. I tried solving this problem by moving the iAd's position with this code:

-(void)hideBanner:(BOOL)sender {
   if (sender) {
      [bannerView setCenter:CGPointMake([CCDirector sharedDirector].winSize.width/2,
                                        320+bannerView.frame.size.height/2)];
   }
   else {
      [bannerView setCenter:CGPointMake([CCDirector sharedDirector].winSize.width/2, 
                                        320-bannerView.frame.size.height/2)];
   }
}

On the scene I added the HUD layer I have a button that calls a function that switches scene to another and calls the function above using this code:

hudLayer *a = [[hudLayer alloc] init];
[a hideBanner:YES];

The function gets called but the iAd doesn't move. I tried calling the same function from the HUD layers init function and the iAd gets moved but not when another scene calls it.

Arbitur
  • 38,684
  • 22
  • 91
  • 128
  • isn't it setFrame? Also you create a new hudlayer, if anything you should call it on the existing one – CodeSmile Apr 07 '13 at 08:39
  • I think its weird that i cant move it before i switch scene but i can when i call the hideBanner function in the init function of hudLayer. And the most weird thing is that the hudlayer was added in another scene and still exists when i switch scene. – Arbitur Apr 07 '13 at 10:48
  • The last thing is to be expected, cocos2d doesn't magically clean up UIKit views for you, that's totally up to you. From what I remember iAd also has code that ensures that the ad is actually displayed on the screen, to prevent developers from getting money for ads the user never sees because they're offscreen or behind another view - this could be an issue here. – CodeSmile Apr 07 '13 at 18:57

0 Answers0