Creating Secondary Live Tiles in Windows Phone XNA Games

Despite Microsoft’s efforts to steer developers away from XNA, until MonoGame and Unity are out of active development, XNA is still the easiest way to create fast-paced and multimedia-intensive games for Windows Phone 7.5, 7.8 and 8.0. With XNA not being updated to support the new features of Windows Phone 8, you’ve probably heard that XNA can only target the Windows Phone 7.1 API, but that’s not true. In this post I am going to explain the necessary steps to getting your XNA game using secondary Live Tiles via the MangoPollo open-source project when it’s run on Windows Phone 7.8 or 8.0.

Recently I wanted to update my Ener-Jewels XNA games for WP7.8 and 8.0 in order to complete a developer challenge on Nokia’s DVLUP site. The games run on the new OSes just fine, but there was a requirement that any game entered in the challenge would need to support all three new sizes of Live Tiles. To do that, I downloaded the MangoPollo code that includes a Silverlight demo and after some trial and error, found a simple way to use the library in XNA too. Here are the steps:

  1. Create your XNA game project and add a reference to the Mangopollo.dll
  2. Add a folder for the Live Tile graphics assets to your game project
  3. Set the Build Action for these Live Tile graphics to “None” and specify “Copy if Newer”
  4. Be sure you’re using Mangopollo.Tiles;
  5. Call a function like the one below to create your Live Tile

private void CreateFlipTileWide_Click() {
if (!Utils.CanUseLiveTiles) {
System.Windows.MessageBox.Show("This feature needs Windows Phone 8");
return;
}

try {
// The Assets folder should be in your game's startup project.
// The images in the Assets folder must specify Build Action as None and Copy if Newer.
// Unfortunately, you cannot specify a separate WideBackTitle in the FlipTileData below.

var mytile = new FlipTileData
{
Title = "Your Great Game", //medium & large tile front bottom
BackTitle = "MangoPollo XNA Demo", //medium & large tile back bottom
BackContent = "MangoPollo", //medium tile back top
WideBackContent = "For MangoPollo to work with XNA, use \"/?arg=val\" in the ShellTileExt.Create call", //large tile back top (maximum of 3 lines of text)
Count = 9, //comment this line out and no Count will be displayed on the tile
SmallBackgroundImage = new Uri("/Assets/logo159x159.png", UriKind.Relative),
BackgroundImage = new Uri("/Assets/Background336x336_1.png", UriKind.Relative),
BackBackgroundImage = new Uri("/Assets/Background336x336_2.png", UriKind.Relative),
WideBackgroundImage = new Uri("/Assets/Background691x336_1.png", UriKind.Relative),
WideBackBackgroundImage = new Uri("/Assets/Background691x336_2.png", UriKind.Relative)
};

// You can set one or more name-value-pair after the "/?" - useful if you want to allow the user to
// create more than one Live Tile and still have your game know which one launched the game.

ShellTileExt.Create(new Uri("/?msg=from%20wide%20flip%20tile", UriKind.Relative), mytile, true);
}
catch {
System.Windows.MessageBox.Show("remove tile before create it again");
}
}

The only real difference between this code and the similar function in the Silverlight demo is the URI in the ShellTileExt.Create call. In Silverlight, the URI is set to the main page of the app, for example, MainPage.xaml. But in XNA there is no XAML or standard concept of a “main page” file – we primarily just want to launch the game’s xap file when the Live Tile is tapped. Windows Phone uses the URI of title container to launch XNA game .xap files. So rather than the URI being “/MainPage.xaml/?name=val”, as it is in Silverlight apps, we would instead use “/?name=val” in an XNA game.

Note that while this code will run in your WP7.5 game, the ability to add the Live Tile will only be there when the game is run on Windows Phone 7.8 or 8.0. Also note that the XNA demo only includes creating a Wide Flip Tile, even though any of the secondary Live Tile types can be created in a similar manner. See the Silverlight demo for examples of creating the other Live Tile types and similarly modify the URI to use it with XNA.

I’ll be sending my XNA demo project to the authors of Mangopollo today and hopefully they’ll add the missing parts of the Silverlight demo into it and include the XNA demo in the next release of Mangopollo. But if you want to check out the XNA demo now – you can find the code here: Mangopollo 1.3 – Silverlight & XNA.zip

Feel free to leave a comment if you have any questions about this.

Tags: , , , , ,
Posted in Code Tutorial by Dan Colasanti. 1 Comment

Clearing an XNA Game’s Default Tile Title in VS2012

When Visual Studio sees a cleared “Tile title” field in your Windows Phone project’s XNA Game Studio properties, it replaces the cleared tile title with “Default tile” when your game is pinned to the Start Screen. It doesn’t do this in the Xbox Games hub, just on the Start Screen. I’ve always found that to be rather annoying – Visual Studio should never rename your tile title, even if you left it blank.

The tile graphic of many games often include a stylized version of the game’s name already. Case in point – Pac-Man:

Requiring developers to then display the name again on the tile graphic (A) is redundant and (B) usually causes the tile title to blend into the background and become unreadable. Should it really be necessary to write the game’s name in tiny white letters over the bottom-left corner of the Pac-Man logo or any of these Windows Phone game tiles?

If you answered “No!”, you are correct! ;-)

In Visual Studio 2010 it was possible to remove the “Default tile” text by replacing the Tile Title field with a whitespace character as long as you put it there right before you built your XNA game into the final .xap. After the build, Visual Studio would trim the whitespace character from the Tile Title field and if you rebuilt the game without replacing it, you again would get “Default tile”. While after-the-build seems like a strange time to trim characters, at least this probable bug allowed XNA devs to clear the tile title if they wanted to.

In VS2012, Microsoft changed the behavior, and putting a whitespace (space-bar) character for the Tile Title no longer shows a blank tile label when the tile’s pinned to the start screen – it instead shows “Default tile”. How nice of them. Fortunately I discovered a new work-around for this – to use an ALT-255 character instead of a space-bar character for the whitespace. Here’s a simple way to create an ALT-255 character:

(1) open Notepad
(2) Hold down the ALT key while typing 255 and then release the ALT key
(3) Select and copy (CTRL-C) the ALT-255 whitespace character that you just created
(4) and paste (CTRL-V) it into your project Properties “XNA Game Studio” tab’s Tile Title field.

Do a build and install the xap to your device or the emulator. Then pin it to the start screen to verify that the tile title is blank. Note that Visual Studio 2012 ironically deletes the ALT-255 character after the build, just like VS2010 did with the space character, so you will still need to do this right before your final build.

Hopefully using ALT-255 in this manner will continue to work in XNA Game Studio on Visual Studio 2012 at least until Microsoft releases the next version of Visual Studio (or XNA Game Studio!). And if you’re reading this, Microsofties, please stop replacing blank Tile Titles with “Default tile”. Thanks.

Tags: , ,
Posted in Visual Studio by Dan Colasanti. No Comments

Getting the Windows Phone 7.8 Update The Easy Way

Back in 2010, I was one of the lucky software developers who received an LG Developer Phone from Microsoft and since then I’ve added an HTC Surround, a Samsung Focus, and Nokia Lumia 800 and 900 phones to my Windows Phone collection. For most of last year I was planning to upgrade at least a couple of them to Windows Phone 8 when it was released and was quite disappointed to find out that I couldn’t. Windows Phone 7.8 is the best OS that Windows Phone 7 handsets can get. And so in October I started waiting for an OS update which was finally released in late January, but as of last week not even one of my phones had received it. They were all still running Windows Phone 7.5 (builds 7720 & 7740).

Now I am not known for being a patient person although for these past 5 months I had tried hard to be one – but now my patience had finally run out. I wanted my upgrade to WP7.8 and I wanted it now! I first tried the Zune trick that put Mango (7.5) on my Focus in 2011 (unplugging the Ethernet cable during an OS Update request), but it didn’t work. So I tried it again with a .bat file that executed ipconfig /release and /renew during the Update request, and that didn’t work either. A full hour: wasted. The trick either doesn’t work anymore because Zune has been patched or because Verizon FIOS is just so much faster than the DSL service I had in 2011.

I started searching to see if someone had cracked an ARM binary that could be flashed when I suddenly found a tool called SevenEighter at WindowsPhoneHacker.com that claimed the ability to easily update Windows Phones to 7.8. I was a little skeptical at first, but after reading many user success stories and noting that the tool actually gets the OS updates from Microsoft’s own servers, I decided to give it a try. The result: instant success!

I used SevenEighter to quickly update 3 of my phones, leaving the Samsung Focus running 7.5 for development & testing purposes. And that old LG developer phone prototype? Well, it’s still stuck on 7.0 and forever will be – even SevenEighter can’t connect to it.

So if you’re still stuck on Windows Phone 7.5 and have run out of patience waiting for the 7.8 update to arrive, skip the quirky Zune tricks and go straight for SevenEighter. You’ll be glad you did!

For the record, it seems very odd to me that registered Windows Phone developers don’t get new phone operating systems ahead of time and aren’t able to flash any available OS to their developer phones whenever they want to. I hope that Microsoft changes their policies regarding these things going forward.

Thanks, WindowsPhoneHacker!

Tags: ,
Posted in Windows Phone OS by Dan Colasanti. Comments Off

Texas Grandmother Proves That Infinity Can End!

Quick! Someone tell Stephen Hawking! A Texas grandmother has proven that Infinity can end!

Judy with Her Contest Prize!

Of course, I am referring to “Ener-Jewels Infinity”, but I’m sure that Mr. Hawking would want to know about Judy Milburn’s great accomplishment none-the-less. You see, about two years ago I launched a promotional contest for ImproviSoft’s “Ener-Jewels!” game called “Can Infinity Ever End?”. In this contest, the first player to max-out the Ener-Jewels Infinity scoreboard and submit a screenshot of it was going to win an XBOX 360 Digital Entertainment Holiday Bundle including an XBOX 360 console, Kinect sensor, 7 XBOX games, and more! I had given out prizes for playing Ener-Jewels before, but this was definitely our most difficult contest and our best prize to date.

Anyone who tried will tell you that maxing-out the Infinity scoreboard is no simple task. You can play for days, weeks, or even months and get nowhere near the maximum score. And so I waited as nearly two years went by with no winner – occasionally replying to email where someone would ask what the max-score was (“Sorry, that’s a secret!”), or asking some variation of “I have over 100,000,000 points – am I close?”, or whether someone had already won. Of course, “close” is such a meaningless word when you are referring to infinity, isn’t it?

Then one day, Judy’s husband Derryl sent me an email that claimed “my wife has over 4 billion points on Infinity” and I knew that if he wasn’t pulling my leg, Judy was closer to winning than anyone had ever been. And just a few days later – Judy had Won! Mobile gaming – it’s not just for kids anymore!

In case you’re wondering, I can now say that the Ener-Jewels Infinity maximum score is 4,294,967,295 points. Yep, that’s more points than Texas has rattlesnakes (I think)! I’m very glad that Judy enjoyed playing Ener-Jewels enough to reach this incredible score and I’m quite sure that I was as excited to ship Judy’s prize as she was to win it!

Now I just have to think up another Ener-Jewels promotion. Hmmm… how am I going to ever top that? I don’t really know, but I’ll think of something! So if you haven’t yet downloaded Ener-Jewels! or Ener-Jewels TGIF! for your Windows Phone, you might want to download it now, before you miss out on another great prize!


The Ener-Jewels Game

Congratulations, Judy, and thanks for playing Ener-Jewels!