• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Joanna Qian
Stay Hungry, Stay Foolish!
博客园    首页    新随笔    联系   管理    订阅  订阅
HTML5开发-在你的游戏应用中加入广告(转)

如何利用lufylegend.js开源引擎在游戏中加入广告。利用lufylegend.js引擎1.7.2版中的新功能LStageWebView,可以在html中加入一个iframe用来显示一个外部页面,我们可以利用这个功能来显示广告。

lufylegend.js引擎官网

http://lufylegend.com/lufylegend

我使用了google adsense广告,当然你也可以使用其他广告,方法一样,好了现在开始。

第一步,你要有一个网站。

第二步,要在google adsense申请注册一个广告。

注:会根据你网站的内容进行审核,申请不通过的话,可以好好看一下google adsense的协议

第三步,在网站上建一个html文件,加入广告代码。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-20477800********";
google_ad_slot = "2255******";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</body>
</html>

上面的js代码,在google adsense的管理页面可直接获取,很简单。

第四步,在游戏中加入以下代码。

    var webView = new LStageWebView();  
    webView.setViewPort(new LRectangle(10,680,LGlobal.width,60));  
    webView.loadURL("http://lufylegend.com/ad/game_vertical_01.html");  
    webView.show();  

loadURL函数是所要显示的外部网页地址,我这个地址是我在第三步所建的html。 完成了,测试连接:

http://lufylegend.com/demo/GemGemAd/

运行效果如下:

LStageWebView使用起来很简单,更详细的使用,可以参照一下官方的API文档

http://lufylegend.com/lufylegend/api

最后,lufylegend.js引擎官网

http://lufylegend.com/lufylegend

转载: http://blog.csdn.net/lufy_legend/article/details/8837691

posted on 2013-04-27 22:26  Joanna Qian  阅读(577)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3