Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用cocos2d的Admob间质性ad_C++_Ios_Admob_Cocos2d X - Fatal编程技术网

C++ 使用cocos2d的Admob间质性ad

C++ 使用cocos2d的Admob间质性ad,c++,ios,admob,cocos2d-x,C++,Ios,Admob,Cocos2d X,我正在使用cocos2d-x为IOS开发一款游戏。现在,我正试图与Admob一起实施间隙广告。我希望它们出现在我的GameOver场景中(就像我在其他游戏中看到的那样) 有人知道怎么做吗 这就是我的GameOver场景的样子: // // IntroScene.m // Cocos2DSimpleGame // // Created by Martin Walsh on 18/01/2014. // Copyright Razeware LLC 2014. All rights rese

我正在使用cocos2d-x为IOS开发一款游戏。现在,我正试图与Admob一起实施间隙广告。我希望它们出现在我的GameOver场景中(就像我在其他游戏中看到的那样)

有人知道怎么做吗

这就是我的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];

Cocos2d-x为Admob提供了一个插件,但该插件的中间部分并不完整,这意味着您必须使用Objective-C编写一些接口代码

如果您还没有解决这个问题,请务必查看PluginAdmob。这将是一个很好的起点。

尝试以下方法:

@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");
    }
}
@import GoogleMobileAds;
@接口类()
@性质(非原子,强)GaD间质*间质;
@结束
@类的实现
-(id)init
{
if((self=[super init])){
self.interstival=[self createandloadinterstival];
//在这里添加您的代码
}
}
-(GadInterstitual*)创建并加载Interstitual{
间隙的=
[[GadInterstitual alloc]initWithAdUnitID:@“您的ADMOB单位ID”];
interstitual.delegate=self;
[间隙加载请求:[GADDRequest]];
返回间隙;
}
#布拉格马克-伽达勒盖特
-(空白)间质IDDISSISSCREEN:(GADInterchyl*)间质{
self.interstival=[self createandloadinterstival];
}
-(空)间隙的
{
if(自间隙已就绪){
[self.interstitial presentFromRootViewController:[CCDirector sharedDirector]];
}否则{
NSLog(@“Ad未准备就绪”);
}
}