使用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。这将是一个很好的起点。
相关文章:
- 初始化派生结构的基部分/意外打包派生结构字段以对齐基结构的间隙
- 构造对象 c++ (cocos2d-x) 时的区别
- C++堆栈中数组之间的间隙
- 如何避免 Cocos2d-x 3.15.1 中的 MenuItemImage 和 MenuItemSprite 之间的冲突
- Cocos2D-X:从内存中读取 MP3 数据
- 如何在 cocos2d-x 3.17v 中创建字符串数组
- 如何使用 cocos creator 在 Cocos2d-X/Cocos2d-JS 中调用 javascript 函数并
- 音乐和音效无法在win32平台上播放?(Cocos2D-X)
- Cocos2d-x TiledMap,在调用 getLayer() 获取碰撞层时返回一个 nullptr?
- 为什么精灵在 cocos2d-x 中颤抖
- 如何在串行通信中插入间隙?
- lambda回调中Android Cocos2D-X应用程序上的SEG故障
- COCOS2D-X 3.0时间表错误2276
- gldrawarrays with cocos2d根本没有绘画
- 内存相关崩溃:Cocos2d游戏中的三维数组
- cc.game.restart() carsh when extend sdkbox in cocos2d-js 3.1
- 如何在Cocos2d Android应用程序中获得呼叫/挂起事件
- 如何在 cocos2d-x 中创建自定义操作
- 使用cocos2d制作间隙广告
- cocos2d-x ResolutionPolicy::SHOW_ALL显示漂亮的图像,而不是黑色的间隙