1

i'm using Cocos2d-iphone v3.0 combined with sprite-builder to build my app.I just recently got iAd working following the answer seen here: How to add iAd in Cocos-SpriteBuilder

So i wont repeat any of the code, the only thing I changed from the posted answer was _adView to _bannerView in init statement. Now I have adds showing where I want but I dont know how to hide them. I would like to have the adds only visible in the game scene after you loose. When you loose I run a gameover event that displays your highscore and a restart button amongst other things so setting a variable like canShowAds to true there and false when the scene starts seems like what I would have to do but I don't know how to only run the ads when its equal to true. Also I plan on having a remove ads button so I would need to check if that has been purchased. If you need anymore code posted I will gladly post it. :)

Community
  • 1
  • 1
BasedRebel
  • 11
  • 5

1 Answers1

3

Try this:

-(void)hideBannerView
{
    if (!_adBannerViewIsVisible)
    {
        return;
    }

    if (_adBannerView)
    {
        _adBannerViewIsVisible = false;

        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

        CGSize s = [[CCDirector sharedDirector] viewSize];


        CGRect frame = _adBannerView.frame;

        if(isBannerOnTop) //use any one..
        {
            frame.origin.x = 0.0f;
            frame.origin.y = -_adBannerView.frame.size.height ;
        }
        else
        {
            frame.origin.x = 0.0f;
            frame.origin.y = s.height ;
        }

        _adBannerView.frame = frame;

        [UIView commitAnimations];
    }

}

Checkout This for full Source

Community
  • 1
  • 1
Guru
  • 21,652
  • 10
  • 63
  • 102
  • 1
    Well its funny you answered actually, because I used your example code in another answer and literally just got it working perfectly. So thanks! – BasedRebel Feb 19 '14 at 05:47
  • @BasedRebel, So next time onwards make sure you search in stack overflow before creating question :) – Guru Feb 19 '14 at 06:52
  • I'm not sure but I think the answer I used was posted after I posted mine :) ...and since this is the only way I know of how to directly contact you, and seeing that you have the best and only working examples for ads in cocos2d v3.0 I was wondering if you had one for combining different ad networks together? My goal is to prioritize iAd, then Admob, then revMob for banners. Im using the code you posted in your other answer for my iAd currently, and plan to do the same with your Admob one. How would I go about modifying your examples to both include revMob, and prioritize ad networks? – BasedRebel Feb 19 '14 at 19:28
  • @BasedRebel, this is new question, not related to title: hiding iAd in Cocos2d V3.0, post it as new question, some expert may help. Happy Coding :) – Guru Feb 19 '14 at 19:48