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



是否有办法将UIView转换为EAGLView,或者我应该添加CAlayer ?最好的方法是什么?对于Cocos2d,任何与BuzzCity相关的示例代码都可以

我现在发现了什么----

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);

我正在尝试的是在按钮图像上显示广告…并调用url为广告在buttonAction
如何在我的uiview顶部显示此按钮?

文档 buzzCity广告集成http://docs.buzzcity.net/wiki/IOS_SDK Advanced_Integration_using_BuzzCity_iOS_SDK

你不能把uiview夹在两个cocos节点之间。如果你想要一个广告按钮,将广告作为ui按钮的背景显示,或者通过测试触摸位置是否在广告的框架内,使广告"可触摸"。

首先将图像保存到documents目录

- (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);

finally on button action打开url

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

相关内容

  • 没有找到相关文章

最新更新