1

プライベート クラスを使用してすべてのビューをプログラムで読み込む目的の c に iPhone ゲーム アプリがあります。(nib ファイルを使用せずに) ビューに admob 広告を配置しようとしていますが、動作させることができないようです。admob 広告ビューを init メソッドに配置しようとしましたが、それでもビューが読み込まれません。

ビューをロードするためにデータを初期化する方法のコードを次に示します。

-(id)init
{
    if( (self=[super init]))
    {
        played_ = NO;

        KWSprite* background = [KWSprite spriteWithFile:@"title_background.png"];
        background.position = ccp(winSize_.width/2, winSize_.height/2);

        KWSprite* logo = [KWSprite spriteWithFile:@"logo.png"];
        logo.position = ccp(winSize_.width/2, 260);    

        CCMenuItemImage* start = [CCMenuItemImage itemFromNormalImage:@"start.png" selectedImage:@"start_selected.png" target:self selector:@selector(pressStartButton:)]
        CCMenuItemImage* credit  = [CCMenuItemImage itemFromNormalImage:@"credit.png" selectedImage:@"credit_selected.png" target:self selector:@selector(pressCreditButton:)];
        CCMenuItemImage* iADButton  = [CCMenuItemImage itemFromNormalImage:@"noAdsD.png" selectedImage:@"noAdsD@2x.png" target:self selector:@selector(pressiAdButton:)];

        CCMenuItemImage* howto = [CCMenuItemImage itemFromNormalImage:@"howto.png" selectedImage:@"howto_selected.png" target:self selector:@selector(pressHowtoButton:)];

        CCMenu* menu = [CCMenu menuWithItems:howto, start, credit, iADButton, nil];
        [menu alignItemsHorizontally];
        menu.position = ccp(winSize_.width/2, 40); 
        [self addChild:background];
        [self addChild:logo];
        [self addChild:menu];
    }
    return self;
}
4

1 に答える 1

0

ここでは Cocos2D を使用しているようです。v0.99.5b3 以降のバージョンを使用している場合は、AdMob コードを RootViewController クラス内に配置することをお勧めします。UIKit ビューを OpenGL ビューと組み合わせていないため、OpenGL のパフォーマンスが向上します。

大まかに言うと、GADBannerView を RootViewController のビューに追加してから、Cocos2D OpenGL ビューのサイズを縮小して、広告が確実に表示されるようにする必要があります。これは次のようになります (このコードは、広告が上部に配置されていることを前提としています)。

- (void)showBanner {
  // Frame of the main RootViewController which we call the root view.
  CGRect rootViewFrame = self.view.frame;
  // Frame of the main RootViewController view that holds the Cocos2D view.
  CGRect glViewFrame = [[CCDirector sharedDirector] openGLView].frame;
  // Frame of the GADBannerView
  CGRect bannerViewFrame = bannerView_.frame;
  CGRect frame = bannerViewFrame;
  // The updated x and y coordinates for the origin of the banner.
  CGFloat yLocation = 0.0;
  CGFloat xLocation = 0.0;


  // Move the root view underneath the ad banner.
  glViewFrame.origin.y = bannerViewFrame.size.height;
  // Center the banner using the value of the origin.
  if (UIInterfaceOrientationIsLandscape(toInt)) {
    // The superView has not had its width and height updated yet so use those
    // values for the x and y of the new origin respectively.
    xLocation = (rootViewFrame.size.height -
                    bannerViewFrame.size.width) / 2.0;
  } else {
    xLocation = (rootViewFrame.size.width -
                    bannerViewFrame.size.width) / 2.0;
  }
  frame.origin = CGPointMake(xLocation, yLocation);
  bannerView_.frame = frame;

  if (UIInterfaceOrientationIsLandscape(toInt)) {
    // The super view's frame hasn't been updated so use its width
    // as the height.
    glViewFrame.size.height = rootViewFrame.size.width -
                                    bannerViewFrame.size.height;
    glViewFrame.size.width = rootViewFrame.size.height;
  } else {
    glViewFrame.size.height = rootViewFrame.size.height -
                                    bannerViewFrame.size.height;
  }
  [[CCDirector sharedDirector] openGLView].frame = glViewFrame;

}
于 2012-07-16T18:50:04.673 に答える