您的位置:首页 > Web前端 > HTML5

HTML5开发-在你的游戏应用中加入广告(转)

2013-04-27 22:26 513 查看
如何利用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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: