簡體   English   中英

使用cocos2d投放插頁式廣告

[英]Admob interstitial ad using cocos2d

我正在使用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];

嘗試這個:

@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");
    }
}

Cocos2d-x有一個用於Admob的插件,但是該插件的插頁式部分並不完整,這意味着您將不得不使用Objective-C編寫一些接口代碼。

如果您尚未解決問題,請查看PluginAdmob。 這將是一個很好的起點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM