Introduction of advertisement (AD) in xNa development mode of WP7)

Source: Internet
Author: User
Tags silverlight admob

Yesterday, the younger brother found that he had made a very serious mistake, that is, the C # startup class of lgame. By default, the base of the parent game class is not called. update and base. draw (base is equivalent to the super version of Java), which makes the rendering mechanism of xNa itself unable to take effect (the rendering of lgame itself is normal, but it only means that when the xNa component is introduced, related xNa components will not be rendered, and operations will not be executed ......), Even the advertisement components inserted with xNa cannot be displayed. (If you change the source code, it will be normal to call the above two items in the related function overload part )~

To make up for the loss, the younger brother downloaded some ad sdks that support xNa and improved the interaction between xNa and lgame, the program example is put into the C # version (only empty projects with AD strips and FPS are displayed for ease of application). below is the advertising advertisement provided by Microsoft, examples of mixing third-party xNa ad components wp7adrotator and lgame.

Advertising

Using loon; using loon. utils. debug; using loon. core. graphics; using Microsoft. xNa. framework; using Microsoft. advertising. mobile. xNa; using system. diagnostics; using system. device. location; using system; namespace lgamead {/// <summary> /// construct an xNa listener to display ads /// </Summary> public class adlistener: xnalistener {// advertising testing mark (Microsoft requires that only advertising testing can be started if this parameter is passed) Private Static readonly string applicationid = "t Est_client "; // ad unit ID (only four display modes are supported during the test, namely, image480_80, image480_80, image300_50, and textad. The ID can be customized only after the formal ID is created .) Private Static readonly string adunitid = "image480_80"; private drawablead bannerad; // The advertisement driver Locator (used to locate the physical location of your mobile phone through GPS/agps) Private geocoordinatewatcher gcw = NULL; /// <summary> /// lgame listener interface, used to listen to the construction of the game class in standard xNa /// </Summary> /// <Param name = "game"> </param> Public void create (game) {}/// <summary> /// lgame listener interface, used to listen to initialize startup in standard xNa /// </Summary> Public void initialize (game) {// initialize ADG Amecomponent component, and add it to the adgamecomponent in the game. initialize (game, applicationid); game. components. add (adgamecomponent. current); // create a new advertisement createad (game) ;}/// <summary> // lgame listener interface, used to listen to the standard xNa loadcontent start // </Summary> Public void loadcontent (Game) {}/// <summary> // lgame listener interface, used to listen to the standard xNa unloadcontent startup // </Summary> Public void unloadcontent (Game) {}/// <summary> // lgame listener interface, used to listen to the standard xNa Updatet call in quasi-xNa (called during every frame loop) /// </Summary> Public void Update (game, gametime) {}/// <summary> /// lgame listener interface, used to listen for draw calls in standard xNa (called during every frame loop) /// </Summary> Public void draw (game, gametime) {}/// <summary> /// create an advertisement /// </Summary> private void createad (game) {// create an ad component of the specified size int width = 480; int Height = 80; // locate it at the top of the center of the screen int x = (game. graphicsdevice. viewport. bounds. wi DTH-width)/2; int y = 5; bannerad = adgamecomponent. current. createad (adunitid, new rectangle (X, Y, width, height), true); // Add ad event listening bannerad. erroccurred + = new eventhandler <Microsoft. advertising. aderroreventargs> (bannerad_erroccurred); bannerad. adrefreshed + = new eventhandler (bannerad_adrefreshed); // adgamecomponent is not activated immediately (activated only after GPS positioning is successful. current. enabled = false; // construct the positioner this. gcw = ne W geocoordinatewatcher (); // listens to the locator activity this. gcw. positionchanged + = new eventhandler <geopositionchangedeventargs <geocoordinate> (gcw_positionchanged); this. gcw. statuschanged + = new eventhandler <geopositionstatuschangedeventargs> (gcw_statuschanged); this. gcw. start ();} private void bannerad_adrefreshed (Object sender, eventargs e) {log. debugwrite ("ad received successfully");} private void bannerad_er Roccurred (Object sender, Microsoft. advertising. aderroreventargs e) {log. debugwrite ("ad error:" + E. error. message);} private void gcw_positionchanged (Object sender, geopositionchangedeventargs <geocoordinate> E) {This. gcw. stop (); bannerad. locationlatitude = E. position. location. latitude; bannerad. locationlongpolling = E. position. location. longpolling; adgamecomponent. current. enabled = true; log. debu Gwrite ("device LAT/long:" + E. position. location. latitude + "," + E. position. location. longpolling);} private void gcw_statuschanged (Object sender, geopositionstatuschangedeventargs e) {If (E. status = geopositionstatus. disabled | E. status = geopositionstatus. nodata) {adgamecomponent. current. enabled = true; log. debugwrite ("geocoordinatewatcher status:" + E. status) ;}/// <summary> // lgame monitoring Listener interface, used to listen to the call of dispose in the standard xNa (called only when the game ends) // </Summary> Public void dispose (game, bool disposing) {If (disposing) {If (this. gcw! = NULL) {This. gcw. dispose (); this. gcw = NULL ;}}} public class game1: lfxplus {public override void onmain () {// load default lgame resources (do not perform this operation, the built-in functions such as analog buttons of lgame cannot be used.) xnaconfig. load ("assets/loon. def "); // load the font file (the pre-compiled xNb file can also be loaded under the content) xnafont = new lfont (" assets "," black ", 0, 20); // register the ad listener (Standard xNa event listener) setxnalistener (New adlistener (); // set the startup parameter lsetting setting = new lsetting (); setting. FPS = 60; setting. width = 480; setting. height = 320; setting. showfps = true; setting. landscape = true; // register the initial screen register (setting, typeof (screentest);} public override void ongameresumed () {} public override void ongamepaused (){}}}

Then, we use wp7adrotator, an open-source third-party ad component, to load adduplex ads (AdMob is also supported ).

Using system; using system. windows; using adrotatorxna; using Microsoft. xNa. framework; using Microsoft. xNa. framework. graphics; using Microsoft. xNa. framework. input; using loon. core. graphics; namespace adrotatorexamplexna {/// <summary> // create an xNa listener (a little bit about the so-called xNa listener in lgame. In essence, lgame-xNa is actually an xNa encapsulated vest. Therefore, the actual function of this listener is to display the operation permissions of xNa In the listener after the lgame is processed ~) /// </Summary> public class adlistener: xnalistener {public void create (game gamne) {} public void initialize (Game) {// initialize adrotatorxnacomponent. initialize (game); // enter the following for hard encoding: // adrotatorxnacomponent. current. pubcenterappid = "test_client"; // adrotatorxnacomponent. current. pubcenteradunitid = "image480_80"; // adrotatorxnacomponent. current. adduplexappid = "0"; // adrotatorxnacomponent. c Urrent. inneractiveappid = "davidecleopadre_clockalarmnightlight_wp7"; // adrotatorxnacomponent. current. mobfoxappid = "474b65a3575dcbc261090efb2b996301"; // adrotatorxnacomponent. current. mobfoxistest = true; // enter the following when reading the configuration file (in this example, the adduplex test advertisement is read, and adrotator also supports the AdMob advertisement) // locate the adrotatorxnacomponent. current. adposition = new vector2 (0,720); // sets the default advertising image adrotatorxnacomponent. current. defaulthouseadimage = Ga Me. content. Load <texture2d> (@ "content/adrotatordefaadadimage"); // click this operation when the default advertisement is clicked. Adrotatorxnacomponent. current. defaulthouseadclick + = new adrotatorxnacomponent. defaulthouseadclickeventhandler (current_defaulthouseadclick); // It is used to select adrotatorxnacomponent in the pop-up direction of the AD phantom effect. current. slidingaddirection = slidedirection. none; // select the local advertising configuration file address (for different advertisers, the configuration effect is different here, depending on the configuration method provided by the specific advertisers) adrotatorxnacomponent. current. defaultsettingsfileuri = "defaultadsettings. XML "; // set the remote configuration file (optional, optional) adrotatorxnacompon Ent. current. settingsurl = "http://xna-uk.net/adrotator/XNAdefaultAdSettingsV2.xml"; // Add ad components to the xNa screen in game. components. add (adrotatorxnacomponent. current);} void current_defaulthouseadclick () {try {MessageBox. show ("Thank you very much for clicking the younger brother's advertisement pai_^");} catch {}} public void loadcontent (Game) {} public void unloadcontent (game) {} public void Update (game, gametime) {} public void draw (GAM E game, gametime) {}public void dispose (game, bool close) {}} public class game1: lfxplus {public override void onmain () {// load the default resources of the lgame (this operation is not performed, and functions such as the built-in analog buttons of the lgame cannot be used) xnaconfig. load ("content/loon. def "); // load the font file (this is a pre-compiled xNb file PS: When the Custom Resource folder is named content, // The package will be automatically merged with the standard content folder. Here is a demonstration. In addition, files are not case sensitive in windows.) xnafont = new lfont ("content", "black", 0, 20 ); // register the ad listener (Standard xNa event listener) setxnalistener (New adlistener (); // set the startup parameter lsetting setting = new lsetting (); setting. FPS = 60; setting. width = 480; setting. height = 320; setting. showfps = true; setting. landscape = false; // register the initial screen register (setting, typeof (screentest);} public override void ongameresumed () {} public override void ongamepaused (){}}}


Although many ad vendors currently only support Silverlight ad sdks, considering the contributions of third-party developers outside China, almost all common WP7 ad sdks (outside China ), there are ways to deploy through xNa, not necessarily supported by Silverlight.

-But domestic advertisers seem to be less lucky.

Today (Tuesday) tested the Silverlight + xNa mix, as expected to achieve a good implementation, has added a new LSilverlight-0.3.3.dll named file and the relevant source code to the WP7 part, after the upload on Friday, Silverlight will be supported (not immediately, because the younger brother has multiple versions (Java, C #, C/C ++, HTML5 (JS )), you can only save enough corrections to get-_-|). The specific statement is as follows:

Namespace lgametest {using system. windows; using system. windows. navigation; using loon. core. graphics; using loon. core. input; using loon. core. timer; using loon. core. graphics. openGL; using Microsoft. phone. controls; public class screentest: screen {public override ltransition ontransition () {return ltransition. newempty ();} public override void onload () {} public override void alter (LT Imercontext c) {} public override void draw (glex g) {} public override void touchdown (ltouch touch) {} public override void touchdrag (ltouch E) {} public override void touchmove (ltouch e) {} public override void touchup (ltouch touch) {}} // Microsoft specifies that the phoneapplicationpage here must be the original class, therefore, when using Silverlight, lgame can only use the following loading method ...... Public partial class gamepage: phoneapplicationpage {lsilverlightplus plus; Public gamepage () {initializecomponent (); // load Silverlight data to lgame plus = lsilverlightplus. load (this, (application. current as APP ). content, onmain );} /// <summary> /// initialization event /// </Summary> /// <Param name = "plus"> </param> Public void onmain (lsilverlightplus plus) {// load the default resources of the lgame (this operation is not performed, and functions such as the built-in analog buttons of the lgame cannot be used) xnaconfig. loa D ("assets/loon. def "); // load the font file (this is a pre-compiled xNb file, you can also load the file under the content) plus. xnafont = new lfont ("assets", "black", 0, 20); // set the startup parameter lsetting setting = new lsetting (); setting. FPS = 60; setting. width = 480; setting. height = 320; setting. showfps = true; setting. landscape = false; // register the initial screen plus. register (setting, typeof (screentest);} protected override void onnavigatedto (navigationeventargs e) {If (plus! = NULL) {plus. onnavigatedto (E); base. onnavigatedto (e) ;}} protected override void onnavigatedfrom (navigationeventargs e) {If (plus! = NULL) {plus. onnavigatedfrom (E); base. onnavigatedfrom (e );}}}}

In order to take into account third-party advertisers in China, the younger brother will add a mixed class library of Silverlight + xNa on Friday (in fact, the code modification volume is small, mainly concentrated on the rendering and input/output interfaces, but the younger brother won't appear out of thin air if he doesn't ...... Wangtian ......), The above corrections will be uploaded to SVN together.

--------------

The following is a video of comparison between Microsoft and the Apple tablet, which begins to work in 55 seconds.

Comparison video between Apple iPad and Microsoft Surface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.