2014-10-08 186 views
0

我正在使用cocos2d-x爲iOS的遊戲工作。現在我試圖通過Admob實施插頁式廣告。我希望他們能夠在我的GameOver場景中彈出(就像我在其他遊戲中看到的一樣)。使用cocos2d的Admob插頁式廣告

有誰知道該怎麼做?

這是我GAMEOVER場景看起來像:

// 
// IntroScene.m 
// Cocos2DSimpleGame 
// 
// Created by Martin Walsh on 18/01/2014. 
// Copyright Razeware LLC 2014. All rights reserved. 
// 
// ----------------------------------------------------------------------- 

// Import the interfaces 
#import "GameOverClass.h" 
#import "HelloWorldScene.h" 
#import "AppDelegate.h" 
#import "GADInterstitial.h" 
#import "GADInterstitialDelegate.h" 


// ----------------------------------------------------------------------- 
#pragma mark - IntroScene 
// ----------------------------------------------------------------------- 

@implementation GameOverClass 
int score1; 
Boolean newhighscore; 


// ----------------------------------------------------------------------- 
#pragma mark - Create & Destroy 
// ----------------------------------------------------------------------- 

+ (GameOverClass *)scene 
{ 
    return [[self alloc] init]; 

} 

// ----------------------------------------------------------------------- 

- (id)init 
{ 

    // Apple recommend assigning self with supers return value 
    self = [super init]; 
    if (!self) return(nil); 

    CCNodeColor *background = [CCNodeColor nodeWithColor:[CCColor colorWithRed:0.1f green:0.7f blue:1.0f alpha:1.0f]]; 
    [self addChild:background]; 

    CCSprite *logo = [CCSprite spriteWithImageNamed:@"gameover.png"]; 
    logo.position = CGPointMake(self.contentSize.width/2, self.contentSize.height - logo.contentSize.height); 
    logo.zOrder = 10; 
    [self addChild:logo]; 
    /* 
    CCSprite *high = [CCSprite spriteWithImageNamed:@"highscore.png"]; 
    high.position = ccp(0.5f, 0.75f); 
    high.zOrder = 10; 


    [self addChild:high]; 
    */ 
    // Spinning scene button 
    CCButton *spinningButton = [CCButton buttonWithTitle:@"[ Try Again ]" fontName:@"Verdana-Bold" fontSize:18.0f]; 
    spinningButton.positionType = CCPositionTypeNormalized; 
    spinningButton.position = ccp(0.5f, 0.35f); 
    spinningButton.zOrder = 10; 
    [spinningButton setLabelColor:[CCColor colorWithRed:1.0f green:0.7f blue:0.0f alpha:1.0f] forState:CCControlStateNormal]; 
    [spinningButton setTarget:self selector:@selector(onSpinningClicked:)]; 
    [self addChild:spinningButton]; 

回答

-2

的Cocos2D-X具有適用於AdMob一個插件,但是該插件的空隙部分沒有完成,這意味着你將不得不寫一些接口代碼與Objective-C。

如果你還沒有解決這個問題,請看看PluginAdmob。這將是一個很好的起點。

0

試試這個:

@import GoogleMobileAds; 

@interface YourClass() <GADInterstitialDelegate> 

@property(nonatomic, strong) GADInterstitial *interstitial; 

@end 

@implementation YourClass 
-(id) init 
{ 
    if((self = [super init])) { 
     self.interstitial = [self createAndLoadInterstitial]; 
     //add your code here 
    } 
} 

- (GADInterstitial *)createAndLoadInterstitial { 
    GADInterstitial *interstitial = 
    [[GADInterstitial alloc] initWithAdUnitID:@"YOUR_ADMOB_UNIT_ID"]; 
    interstitial.delegate = self; 
    [interstitial loadRequest:[GADRequest request]]; 
    return interstitial; 
} 

#pragma mark - GADInterstitialDelegate 
- (void)interstitialDidDismissScreen:(GADInterstitial *)interstitial { 
    self.interstitial = [self createAndLoadInterstitial]; 
} 

- (void)showInterstitial 
{ 
    if (self.interstitial.isReady) { 
     [self.interstitial presentFromRootViewController:[CCDirector sharedDirector]]; 
    } else { 
     NSLog(@"Ad wasn't ready"); 
    } 
}