如何在cocos2d项目中显示广告横幅(buzzcity)?

时间:2013-05-18 05:35:29

标签: cocos2d-iphone admob eaglview adbannerview

有没有办法通过将UIView转换为EAGLView来放置CAlayer,还是应该添加BuzzCity? 什么是最好的方法呢? 任何与Cocos2d btnAD = [CCMenuItemImage itemFromNormalImage:@"underwater-images-paradox-visual-wallpapers-title-search-196522.jpg" selectedImage:@"underwater-images-paradox-visual-wallpapers-title-search-196522.jpg" target:self selector:@selector(AdbuttonAction)]; btnAD.position=ccp(0, 0); 相关的示例代码都不错

到目前为止我发现了什么----

uiview

我想要的是在按钮图片上显示广告...... 并在 buttonAction
上调用广告的网址 如何在{{1}}上面显示此按钮?

buzzCity广告集成的

文档 http://docs.buzzcity.net/wiki/IOS_SDK#Advanced_Integration_using_BuzzCity_iOS_SDK

2 个答案:

答案 0 :(得分:0)

你不能将UIViews夹在两个cocos节点之间。如果您想要广告按钮,请将广告显示为UIButton的背景,或者只是通过测试触摸位置是否在广告框架内来使广告“可触摸”。

答案 1 :(得分:0)

首先我将我的图像保存到文档目录

- (NSString *)saveImage {
    NSURL *url = [NSURL   URLWithString:@"http://ads.buzzcity.net/show.php?partnerid=8404&browser=app_apple"];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *image = [UIImage imageWithData:data];
      //convert image into .png format.
    NSData *imageData = UIImagePNGRepresentation(image);
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:@"myImage"];
    [imageData writeToFile:fullPath atomically:YES];
    NSLog(@"image saved");
    return fullPath;

}

然后我添加了**itemFromNormalImage:fullPath**

的路径
NSString *fullPath=[self saveImage];
    btnAD = [CCMenuItemImage itemFromNormalImage:fullPath selectedImage:fullPath target:self selector:@selector(AdButtonAction)];

        NSLog(@"btnAD %@", btnAD);

    CCMenu *adMenu = [CCMenu menuWithItems:btnAD, nil];
    [self addChild:adMenu];
    adMenu.position = ccp(350 ,size.height-50);

最后按钮操作打开网址

-(void)AdButtonAction
{
  NSURL *url = [NSURL URLWithString:@"http://click.buzzcity.net/click.php?partnerid=8404&browser=app_apple"];
  NSLog(@"url = %@",url);
  [[UIApplication sharedApplication] openURL:url];
}