Click here to Skip to main content
13,290,261 members (54,547 online)
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 24 Oct 2012

AdRotator for Windows Phone XNA

, 24 Oct 2012
Rate this:
Please Sign up or sign in to vote.
AdRotator for Windows Phone XNA

Icon_1_purple image

AdRotator for Windows Phone XNA V0.3 Release

Hot on the heels of the Silverlight article for AdRotator is the documentation for the XNA version, to save repeating myself I’d suggest you read that first to get the general look and feel of AdRotator before continuing. I’m only going to go over the XNA implementation parts in this article.

In some ways, the XNA implementation is even easier than Silverlight because we don’t have to worry about all the GUI stuff, if you are doing a SilverXNA project (Silverlight / XNA integration) then either route will work fine (or both Open-mouthed smile).

Basic Nuts and Bolts

Just like with the Silverlight version, go and download all the binaries from the AdRotator codeplex site and copy them to your project, then add the references to the XNA libraries, you’ll notice there are far fewer of them because most don’t provide a native API so we have had to use the Web API for those.

Once they are in first, you have to initialize the control in the normal XNA “initialize” method:

protected override void Initialize()
	// TODO: Add your initialization logic here
	AdRotatorXNAComponent.Current.AdPosition = new Vector2(0, 720);
	AdRotatorXNAComponent.Current.SlidingAdDirection = SlideDirection.Bottom;
	AdRotatorXNAComponent.Current.DefaultSettingsFileUri = "defaultAdSettings.xml";
	AdRotatorXNAComponent.Current.SettingsUrl = 

To ensure you also display the Ad in the correct orientation, we also recommend hooking up to the “OrientationChanged” event and ensuring that AdRotator is notified, so add the following to the Game Constructor:

Window.OrientationChanged += new EventHandler<EventArgs>(Window_OrientationChanged);

And then adding the corresponding method with the call to AdRotator:

void Window_OrientationChanged(object sender, EventArgs e)

And that’s pretty much it. Just be sure to add the “DefaultAdSettings.xml” config file (or whatever you call it) to the main project NOT the content project updating the above initialize logic accordingly, you can even configure the remote URL for the configuration if you so wish (optional).

Easy as Pie!

Local House AD

Since XNA is all about textures, your local house ad is just a texture image. Just drop it into your content project and then add the following lines to the above initialization logic:

AdRotatorXNAComponent.Current.DefaultHouseAdImage =
AdRotatorXNAComponent.Current.DefaultHouseAdClick +=
	new AdRotatorXNAComponent.DefaultHouseAdClickEventHandler(Current_DefaultHouseAdClick);

Just make sure you also add the corresponding “Click” event handler to do what you want when the user clicks on the link, our samples simply do the following:

void Current_DefaultHouseAdClick()
		MessageBox.Show("You clicked on my Ad, thanks very much");
	catch { }

But you could just as easily start up a web browser task or a marketplace detail task to show more details about your other games

Remote House Ad

The remote house Ad is just as simple, it’ll still use the same “Clicked” event as above (couldn’t remote that I’m afraid at the moment), but all you do is host an image on your website and update the XML configuration to point to it.

AdRotator will check the remote image, download it if it’s changed and cache it locally and then display it when asked.

In either case, the same default rules apply for house Ads, either configure them with a probability or don’t and you can use either a local or remote ad or BOTH.

XNA Couldn’t Be Simpler

As mentioned in the last post, we're still going to deliver Desktop and XBOX versions of the XNA control (XBOX without web of course just a local Ad, multiple in V2).

No XNA in Win 8 yet, so that will be XAML or monogame!

Again, we recommend at the very least you put AdDuplex in your XML configuration, it’s FREE and you get exposure everywhere and is accepted at all major and minor outlets just about everywhere, it’s great as a primary or just as the fall back position.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Simon Jackson
Architect ZenithMoon Studios
United Kingdom United Kingdom
Long time game developer / IT maniac.
By day working as a lowly Technical Architect for a healthcare software firm, by night Masquerading as the Master Chief of ZenithMoon Studios.

At heart I'm a community developer breaking down lots of fun and curious technologies and bringing them to the masses.

I'm also a contributor to several open source projects, most notably the AdRotator advertising rotator project for Windows and Windows Phone.

After a hefty break with Windows Phone and Windows 8 I'm heading back to my XNA roots to show how beginners and current XNA devs can take their skills forward with XNA's bleak future.

ID&Xbox MVP & Best selling author
[Mastering Unity 2D Game Development] (
[Unity 3D UI Essentials] (

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 24 Oct 2012
Article Copyright 2012 by Simon Jackson
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid