1. <legend id='3GU4l'><style id='3GU4l'><dir id='3GU4l'><q id='3GU4l'></q></dir></style></legend>

      <small id='3GU4l'></small><noframes id='3GU4l'>

      <tfoot id='3GU4l'></tfoot>

      1. <i id='3GU4l'><tr id='3GU4l'><dt id='3GU4l'><q id='3GU4l'><span id='3GU4l'><b id='3GU4l'><form id='3GU4l'><ins id='3GU4l'></ins><ul id='3GU4l'></ul><sub id='3GU4l'></sub></form><legend id='3GU4l'></legend><bdo id='3GU4l'><pre id='3GU4l'><center id='3GU4l'></center></pre></bdo></b><th id='3GU4l'></th></span></q></dt></tr></i><div id='3GU4l'><tfoot id='3GU4l'></tfoot><dl id='3GU4l'><fieldset id='3GU4l'></fieldset></dl></div>
          <bdo id='3GU4l'></bdo><ul id='3GU4l'></ul>
      2. 如何在 Cocos-SpriteBuilder 中添加 iAd

        时间:2024-08-12
          <tbody id='fQJVj'></tbody>
              <bdo id='fQJVj'></bdo><ul id='fQJVj'></ul>

              <legend id='fQJVj'><style id='fQJVj'><dir id='fQJVj'><q id='fQJVj'></q></dir></style></legend>

            • <small id='fQJVj'></small><noframes id='fQJVj'>

              1. <tfoot id='fQJVj'></tfoot>
                • <i id='fQJVj'><tr id='fQJVj'><dt id='fQJVj'><q id='fQJVj'><span id='fQJVj'><b id='fQJVj'><form id='fQJVj'><ins id='fQJVj'></ins><ul id='fQJVj'></ul><sub id='fQJVj'></sub></form><legend id='fQJVj'></legend><bdo id='fQJVj'><pre id='fQJVj'><center id='fQJVj'></center></pre></bdo></b><th id='fQJVj'></th></span></q></dt></tr></i><div id='fQJVj'><tfoot id='fQJVj'></tfoot><dl id='fQJVj'><fieldset id='fQJVj'></fieldset></dl></div>
                  本文介绍了如何在 Cocos-SpriteBuilder 中添加 iAd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 SpriteBuilder(与 Cocos2d v3.0 集成).我构建了一个应用程序,现在我想在最顶部放置一个 iAd,当我调用它时它会弹出,当我告诉它时它会隐藏.最简单的方法是什么?

                  I am using SpriteBuilder (which integrates with Cocos2d v3.0). I built an app and now I want to put in an iAd at the very top that pops up when I call it, and hides when I tell it to. What's the simplest way to do this?

                  请记住,我将 SpriteBuilder 与 Cocos2d 一起使用.仅仅因为我使用 SpriteBuilder 并不意味着我也没有使用 Xcode 5.我也完全参与了 Xcode.SpriteBuilder 不会为我编写代码,我会这样做.

                  Keep in mind I am using SpriteBuilder with Cocos2d. And just because I am using SpriteBuilder does not mean I am not using Xcode 5 as well. I am fully involved in Xcode as well. SpriteBuilder does not write the code for me, I do that.

                  推荐答案

                  将 iAd 框架添加到您的依赖项中.

                  Add iAd framework to your dependencies.

                  在游戏场景的头文件中,添加 ADBannerViewDelegate,例如:

                  In your header file for your game scene, add the ADBannerViewDelegate, for instance:

                  @interface MainScene : CCNode <CCPhysicsCollisionDelegate, ADBannerViewDelegate>
                  

                  在你的实现文件中,添加实例变量_bannerView:

                  In your implementation file, add the instance variable _bannerView:

                  @implementation MainScene {
                      ADBannerView *_bannerView;
                  }    
                  

                  最后,插入 iAD 代码(通过一些 cocos2d 调整).这是我对带有顶部横幅的纵向模式游戏的实现.没有 hide 方法,但很容易实现.

                  And finally, insert the the iAD code (with some cocos2d tweaks). Here's my implementation for a game in portrait mode with a top banner. There's no hide method, but it's pretty easy to implement.

                  # pragma mark - iAd code
                  
                  -(id)init
                  {
                      if( (self= [super init]) )
                      {
                          // On iOS 6 ADBannerView introduces a new initializer, use it when available.
                          if ([ADBannerView instancesRespondToSelector:@selector(initWithAdType:)]) {
                              _adView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
                  
                          } else {
                              _adView = [[ADBannerView alloc] init];
                          }
                          _adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
                          _adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
                          [[[CCDirector sharedDirector]view]addSubview:_adView];
                          [_adView setBackgroundColor:[UIColor clearColor]];
                          [[[CCDirector sharedDirector]view]addSubview:_adView];
                          _adView.delegate = self;
                      }
                      [self layoutAnimated:YES];
                      return self;
                  }
                  
                  
                  - (void)layoutAnimated:(BOOL)animated
                  {
                      // As of iOS 6.0, the banner will automatically resize itself based on its width.
                      // To support iOS 5.0 however, we continue to set the currentContentSizeIdentifier appropriately.
                      CGRect contentFrame = [CCDirector sharedDirector].view.bounds;
                      if (contentFrame.size.width < contentFrame.size.height) {
                          _bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
                      } else {
                          _bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
                      }
                  
                      CGRect bannerFrame = _bannerView.frame;
                      if (_bannerView.bannerLoaded) {
                          contentFrame.size.height -= _bannerView.frame.size.height;
                          bannerFrame.origin.y = contentFrame.size.height;
                      } else {
                          bannerFrame.origin.y = contentFrame.size.height;
                      }
                  
                      [UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
                          _bannerView.frame = bannerFrame;
                      }];
                  }
                  
                  - (void)bannerViewDidLoadAd:(ADBannerView *)banner {
                      [self layoutAnimated:YES];
                  }
                  
                  - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
                      [self layoutAnimated:YES];
                  }
                  

                  这篇关于如何在 Cocos-SpriteBuilder 中添加 iAd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何抓取 b2Body 并在屏幕上移动它?(cocos2d,box2d,iphone) 下一篇:cocos2d如何开启多点触控?

                  相关文章

                      <bdo id='VSzlN'></bdo><ul id='VSzlN'></ul>
                  1. <i id='VSzlN'><tr id='VSzlN'><dt id='VSzlN'><q id='VSzlN'><span id='VSzlN'><b id='VSzlN'><form id='VSzlN'><ins id='VSzlN'></ins><ul id='VSzlN'></ul><sub id='VSzlN'></sub></form><legend id='VSzlN'></legend><bdo id='VSzlN'><pre id='VSzlN'><center id='VSzlN'></center></pre></bdo></b><th id='VSzlN'></th></span></q></dt></tr></i><div id='VSzlN'><tfoot id='VSzlN'></tfoot><dl id='VSzlN'><fieldset id='VSzlN'></fieldset></dl></div>

                      <tfoot id='VSzlN'></tfoot>

                      <small id='VSzlN'></small><noframes id='VSzlN'>

                      <legend id='VSzlN'><style id='VSzlN'><dir id='VSzlN'><q id='VSzlN'></q></dir></style></legend>