当前位置: 移动技术网 > 移动技术>移动开发>WP > Windows Phone 7 For XNA 广告盈利

Windows Phone 7 For XNA 广告盈利

2018年10月13日  | 移动技术网移动技术  | 我要评论

 

 “adcertising services”广告服务控件是微软在windows phone平台上推出的赚钱利器,adcertising services可以轻松的帮助开发者在其开发的应用程序或者xna游戏上显示广告。

 


 

使用步骤

  a)下载x?id=8729">microsoft adcertising sdk for windows phone,并安装。安装完成后会你会得到两个框架的,一个是基于sl的,一个是基于xna的。

  b) 登陆pubcenter,pubcenter主要的功能是创建并管理您的广告。在pubcenter中微软提供了贴心的广告解决方案帮你管理你的应用程序中广告的显示次数,盈利分析等功能。需要注意的是,登陆pubcenter时最好使用ie8.0或火狐5.0以上版本登陆,用其他登陆时会出现浏览器兼容问题。

  c) 创建并提交。

 


 

使用流程

  a)注册

      1)开打pubcenter后,使用你的开发者账号登陆。如下图:

 

                   \\

      2)如果你登陆成功的话,恭喜你,你已经离成功不远了 :)。登陆成功后你将完成注册application id、ad units id等工作。如下图:

 

       \

 

         reports:报表,这里主要表述了你的盈利情况,也可以查看广告不同时期的盈利,当然你还可以根据自己的需求来创建一个报表并保存。

         setup:创建广告的入口,下面会详细列出步骤。

       accounts:开发者账号个人信息。

      3)创建你的广告,点击setup将会出现下图

                   \

                   applications:用来创建你的应用程序id。

        ad units:用来创建你广告单元的id。

        global ad exclusions:全球广告排除。添加你要阻止的url。

        channels:广告渠道。

        点击applications->点击register application,见下图:

      

                  \

                  \

        name:因为是测试用,所有名字可以随意起:)

        device type:选不了,默认!

 

                   点击save进行保存来到下个页面。如下图:

 

                 \

 

                   接下来该创建广告单元了,点击setup下面的ad units,在出现的页面中点击create application ad unit,如下图:

 

                 \

 

                   在出现的页面中填入ad unit name,并选择广告单元的大小,这里提供了两种尺寸,见下图:

 

                \

 

                   添加完ad unit name和size后我们还要选择一下广告的类别,在类别选中我们只能选三个。如下图:

 

                  \

                   添加global ad exclusions。如果你不想看到哪个网站的广告,你可以在下面的对话框中填入相应的url。不填写也没问题。

                   点击save进行保存后将出现一个关于ad unit的详细列表,在这个列表中点击ad unit name进行修改,也可以重新创建一个ad unit。如下图:

                   

                 \

      4)说明

         在开发过程中,如果你使用模拟器来查看刚刚申请的广告控件的话,会没有任何广告显示出血来,因为微软怕造成非法广告点击,而且微软的广告控件可以识别程序是否运行在模拟器上,所以在模拟器上广告控件是不会显示的,不过贴心的微软提供了三组测试数据,可以使用这些数据测试广告控件在windows phone 7中的实际效果。

         以下是三组测试数据的测试值,如下图:

                 

                 \

 

  b)在xna中使用adcertising

      首先需要明确的一点是在windows phone for xna中使用adcertising与在windows phone for silverlight中使用adcertising是不同的,在sl中可以直接使用adcertising控件进行控制,而在xna中需要添加相关代码来实现,以下是微软提供的实例代码当然你也可以去加深理解!在自己添加的工作中,别忘记引用microsoft.advertising.mobile.xna.dllmicrosoft.advertising.mobile.xna命名空间!

 

 

//*********************************************************

//

// copyright (c) microsoft. all rights reserved.

// this code is licensed under the microsoft public license.

// this code is provided *as is* without warranty of

// any kind, either express or implied, including any

// implied warranties of fitness for a particular

// purpose, merchantability, or non-infringement.

//

//*********************************************************

using system;

using system.collections.generic;

using system.linq;

using microsoft.xna.framework;

using microsoft.xna.framework.audio;

using microsoft.xna.framework.content;

using microsoft.xna.framework.gamerservices;

using microsoft.xna.framework.graphics;

using microsoft.xna.framework.input;

using microsoft.xna.framework.input.touch;

using microsoft.xna.framework.media;

using microsoft.advertising.mobile.xna;

using system.diagnostics;

using system.device.location;

 

namespace xnagamewithad

{

    /// <summary>

    /// this is the main type for your game

    /// </summary>

    public class game1 : microsoft.xna.framework.game

    {

    

        private static readonly string applicationid = "test_client"; // 如果在实际使用中,需要换成您之前申请的applicationid

        private static readonly string adunitid = "textad"; //other test values: image480_80, image300_50, textad,在实际使用中换成您之前申请的adunitid

     

        graphicsdevicemanager graphics;

        spritebatch spritebatch;

        drawablead bannerad; // bannerad代表一个广告单元

 

        // we will use this to find the device location for better ad targeting.

        private geocoordinatewatcher gcw = null;

 

        public game1()

        {

            graphics = new graphicsdevicemanager(this);

            content.rootdirectory = "content";

 

            // frame rate is 30 fps by default for windows phone.

            targetelapsedtime = timespan.fromticks(333333);           

        }

 

        /// <summary>

        /// allows the game to perform any initialization it needs to before starting to run.

        /// this is where it can query for any required services and load any non-graphic

        /// related content.  calling base.initialize will enumerate through any components

        /// and initialize them as well.

        /// </summary>

        protected override void initialize()

        {

            // initialize the adgamecomponent with your applicationid and add it to the game.

            adgamecomponent.initialize(this, applicationid);

            components.add(adgamecomponent.current);

 

            // now create an actual ad for display.

            createad();

 

            base.initialize();

        }

 

        /// <summary>

        /// loadcontent will be called once per game and is the place to load

        /// all of your content.

        /// </summary>

        protected override void loadcontent()

        {

            // create a new spritebatch, which can be used to draw textures.

            spritebatch = new spritebatch(graphicsdevice);

 

            // todo: use this.content to load your game content here

        }

 

        /// <summary>

        /// unloadcontent will be called once per game and is the place to unload

        /// all content.

        /// </summary>

        protected override void unloadcontent()

        {

            // todo: unload any non contentmanager content here

        }

 

        /// <summary>

        /// allows the game to run logic such as updating the world,

        /// checking for collisions, gathering input, and playing audio.

        /// </summary>

        /// <param name="gametime">provides a snapshot of timing values.</param>

        protected override void update(gametime gametime)

        {

            // allows the game to exit

            if (gamepad.getstate(playerindex.one).buttons.back == buttonstate.pressed)

                this.exit();

 

            // todo: add your update logic here

 

            base.update(gametime);

        }

 

        /// <summary>

        /// this is called when the game should draw itself.

        /// </summary>

        /// <param name="gametime">provides a snapshot of timing values.</param>

        protected override void draw(gametime gametime)

        {

            graphicsdevice.clear(color.cornflowerblue);

 

            // todo: add your drawing code here

 

            base.draw(gametime);

        }

 

        /// <summary>

        /// create a drawablead with desired properties.

        /// </summary>

        private void createad()

        {

            // create a banner ad for the game.

            int width = 480;

            int height = 80;

            int x = (graphicsdevice.viewport.bounds.width - width) / 2; // centered on the display

            int y = 5;

           

            bannerad = adgamecomponent.current.createad(adunitid, new rectangle(x, y, width, height), true);

 

            // add handlers for events (optional).

            bannerad.erroroccurred += new eventhandler<microsoft.advertising.aderroreventargs>(bannerad_erroroccurred);

            bannerad.adrefreshed += new eventhandler(bannerad_adrefreshed);

 

            // set some visual properties (optional).

            //bannerad.borderenabled = true; // default is true

            //bannerad.bordercolor = color.white; // default is white

            //bannerad.dropshadowenabled = true; // default is true

 

            // provide the location to the ad for better targeting (optional).

            // this is done by starting a geocoordinatewatcher and waiting for the location to be available.

            // the callback will set the location into the ad.

            // note: the location may not be available in time for the first ad request.

            adgamecomponent.current.enabled = false;

            this.gcw = new geocoordinatewatcher();

            this.gcw.positionchanged += new eventhandler<geopositionchangedeventargs<geocoordinate>>(gcw_positionchanged);

            this.gcw.statuschanged += new eventhandler<geopositionstatuschangedeventargs>(gcw_statuschanged);

            this.gcw.start();

        }

 

        /// <summary>

        /// this is called whenever a new ad is received by the ad client.

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void bannerad_adrefreshed(object sender, eventargs e)

        {

            debug.writeline("ad received successfully");

        }

 

        /// <summary>

        /// this is called when an error occurs during the retrieval of an ad.

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e">contains the error that occurred.</param>

        private void bannerad_erroroccurred(object sender, microsoft.advertising.aderroreventargs e)

        {

            debug.writeline("ad error: " + e.error.message);

        }

             

        private void gcw_positionchanged(object sender, geopositionchangedeventargs<geocoordinate> e)

        {

            // stop the geocoordinatewatcher now that we have the device location.

            this.gcw.stop();

 

            bannerad.locationlatitude = e.position.location.latitude;

            bannerad.locationlongitude = e.position.location.longitude;

 

            adgamecomponent.current.enabled = true;

 

            debug.writeline("device lat/long: " + e.position.location.latitude + ", " + e.position.location.longitude);

        }

 

        private void gcw_statuschanged(object sender, geopositionstatuschangedeventargs e)

        {

            if (e.status == geopositionstatus.disabled || e.status == geopositionstatus.nodata)

            {  

                // in the case that location services are not enabled or there is no data

                // enable ads anyway

                adgamecomponent.current.enabled = true;

                debug.writeline("geocoordinatewatcher status :" + e.status);               

            }

        }

 

        /// <summary>

        /// clean up the geocoordinatewatcher

        /// </summary>

        protected override void dispose(bool disposing)

        {

            base.dispose(disposing);

 

            if (disposing)

            {

                if (this.gcw != null)

                {

                    this.gcw.dispose();

                    this.gcw = null;

                }

            }

        }

    }

}

 

      让我们看一下运行后的效果,如下图:

 

                 \

        我顺手展示下自己开发的小游戏中加入的adcertising,思路很简单就是在你游戏继承了game的类中createad()下,代码基本跟示例代码一致,但每个游戏的设计会有所不同,根据个人的设计自行调整下就可以了,如下图:

                 

                 \

  

    ok,基本的流程大致就是这样,赶快行动吧!:)

 

摘自 由洋

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网