<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Абструс! &#187; Windows Phone</title>
	<atom:link href="http://www.abstrys.com/category/windows-phone/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.abstrys.com</link>
	<description>Writing, game development, and other enigmatic esoterica.</description>
	<lastBuildDate>Tue, 12 Apr 2011 17:14:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Free eBook available: Programming Windows Phone 7 by Charles Petzold</title>
		<link>http://www.abstrys.com/2011/04/free-ebook-available-programming-windows-phone-7-by-charles-petzold/</link>
		<comments>http://www.abstrys.com/2011/04/free-ebook-available-programming-windows-phone-7-by-charles-petzold/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 17:11:15 +0000</pubDate>
		<dc:creator>Eron</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[XNA Game Studio Docs & Resources]]></category>

		<guid isPermaLink="false">http://www.abstrys.com/?p=142</guid>
		<description><![CDATA[Charles Petzold, the author of Programming Windows has released a book about Programming Windows Phone 7, from the perspective of both the Silverlight and XNA Game Studio application models. It&#8217;s also available in e-book form for&#8230; free!  It&#8217;s a 13MB PDF that can be downloaded from Microsoft Press. Get it before they run out! ]]></description>
			<content:encoded><![CDATA[<p><a href="http://blogs.msdn.com/b/microsoft_press/archive/2010/10/28/free-ebook-programming-windows-phone-7-by-charles-petzold.aspx" target="_blank"><img class="alignright" title="Programming Windows Phone 7, by Charles Petzold" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-17-44-metablogapi/6558.9780735643352x_5F00_thumb_5F00_6E9D86B6.jpg" alt="" width="233" height="284" /></a>Charles Petzold, the author of Programming Windows has released a book about Programming Windows Phone 7, from the perspective of both the <a href="http://msdn.microsoft.com/en-us/library/ff402535%28v=VS.92%29.aspx" target="_blank">Silverlight</a> and <a href="http://msdn.microsoft.com/en-us/library/bb200104.aspx" target="_blank">XNA Game Studio</a> application models.</p>
<p>It&#8217;s also available in e-book form for&#8230; free!  It&#8217;s a 13MB PDF that can be <a href="http://blogs.msdn.com/b/microsoft_press/archive/2010/10/28/free-ebook-programming-windows-phone-7-by-charles-petzold.aspx" target="_blank">downloaded from Microsoft Press</a>. Get it before they run out!  <img src='http://www.abstrys.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.abstrys.com/2011/04/free-ebook-available-programming-windows-phone-7-by-charles-petzold/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creator&#8217;s Club is Dead&#8230; long live&#8230; App Hub?</title>
		<link>http://www.abstrys.com/2010/10/creators-club-is-dead-long-live-app-hub/</link>
		<comments>http://www.abstrys.com/2010/10/creators-club-is-dead-long-live-app-hub/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 00:38:56 +0000</pubDate>
		<dc:creator>Eron</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[App Hub]]></category>
		<category><![CDATA[Creator's Club Online]]></category>
		<category><![CDATA[Xbox 360]]></category>
		<category><![CDATA[XNA Game Studio Docs & Resources]]></category>

		<guid isPermaLink="false">http://www.abstrys.com/?p=118</guid>
		<description><![CDATA[Those of you who have recently tried to access creators.xna.com may have noticed something, well, different. The old Creator&#8217;s Club site is, indeed gone, along with developer.windowsphone.com (the previous Windows Phone Developer portal). Both of these sites have been replaced by the App Hub, a new site featuring a cleaner, more navigable design to enable [...]]]></description>
			<content:encoded><![CDATA[<p>Those of you who have recently tried to access <strong>creators.xna.com</strong> may have noticed something, well, <em>different</em>.</p>
<p>The old Creator&#8217;s Club site is, indeed gone, along with <strong>developer.windowsphone.com</strong> (the previous Windows Phone Developer portal). Both of these sites have been replaced by the <a href="http://create.msdn.com/" target="_blank">App Hub</a>, a new site featuring a cleaner, more navigable design to enable you to find the downloads, samples, tutorials, and articles you&#8217;re looking for to complete your game or application for either (or both!) Xbox 360 or Windows Phone. I, personally, like simplification!</p>
<p>There are also a number of new forums to explore, and the old Creator&#8217;s Club forum content seems to have made the transition intact.</p>
<p>Log in with your Windows LIVE ID, as before&#8230; and get to it!  I look forward to seeing your creations on the Xbox 360 and Windows Phone marketplaces!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.abstrys.com/2010/10/creators-club-is-dead-long-live-app-hub/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Phone 7 Announcements Around the Web</title>
		<link>http://www.abstrys.com/2010/10/windows-phone-7-announcements-around-the-web/</link>
		<comments>http://www.abstrys.com/2010/10/windows-phone-7-announcements-around-the-web/#comments</comments>
		<pubDate>Tue, 12 Oct 2010 20:41:34 +0000</pubDate>
		<dc:creator>Eron</dc:creator>
				<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[Windows Phone 7]]></category>

		<guid isPermaLink="false">http://www.abstrys.com/?p=116</guid>
		<description><![CDATA[Yesterday heralded the official announcement of the availability of Windows Phone 7 devices by Microsoft, and there are a fair number of new devices that will be available—Engadget&#8217;s even posted a nicely-formatted guide to the new phones. This is one of my favorite things about Windows Phone (and is a trait shared by Android, and [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday heralded the official announcement of the availability of Windows Phone 7 devices by Microsoft, and there are a fair number of new devices that will be available—Engadget&#8217;s even posted a <a href="http://www.engadget.com/2010/10/11/windows-phone-7-handsets-the-tale-of-the-tape/" target="_blank">nicely-formatted guide to the new phones</a>.</p>
<p>This is one of my favorite things about Windows Phone (and is a trait shared by Android, and to a lesser extent, Blackberry): the variety in the hardware available.  It gives customers a choice in devices, tailored to suit one&#8217;s individual style. Devices exist, for instance, with slide-out keyboards (in both <a href="http://www.bing.com/search?q=htc+7+pro" target="_blank">landscape</a> and <a href="http://www.bing.com/search?q=dell+lightning" target="_blank">portrait</a> orientations), <a href="http://www.bing.com/search?q=htc+7+mozart" target="_blank">upgraded cameras</a>, <a href="http://www.bing.com/search?q=htc+7+surround" target="_blank">surround-sound speakers</a>, <a href="http://www.bing.com/search?q=samsung+focus" target="_blank">AMOLED</a> screens, and even <a href="http://www.bing.com/search?q=htc+hd7" target="_blank">kickstands</a>.  It&#8217;ll certainly be interesting to see what additional hardware Windows Phone 7 will be paired with in the coming years.</p>
<p>The devices become available for purchase in North America on November 8th, and I <em>certainly </em>look forward to seeing what XNA Game Studio developers create with them!  <img src='http://www.abstrys.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.abstrys.com/2010/10/windows-phone-7-announcements-around-the-web/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Phone Preview at Engadget</title>
		<link>http://www.abstrys.com/2010/07/windows-phone-preview-at-engadget/</link>
		<comments>http://www.abstrys.com/2010/07/windows-phone-preview-at-engadget/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 21:14:43 +0000</pubDate>
		<dc:creator>Eron</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[XNA Game Studio 4]]></category>

		<guid isPermaLink="false">http://www.abstrys.com/?p=106</guid>
		<description><![CDATA[The popular tech blog Engadget recently posted a rather complete preview of what&#8217;s to come with Windows Phone 7. I&#8217;m looking forward to this as well, and am brewing ideas for a few games on the platform. Do give Engadget&#8217;s article a look! If you&#8217;re a game developer familiar with XNA, and especially if you&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>The popular tech blog Engadget recently <a href="http://www.engadget.com/2010/07/19/windows-phone-7-in-depth-preview/" target="_blank">posted a rather complete preview</a> of what&#8217;s to come with Windows Phone 7.</p>
<p>I&#8217;m looking forward to this as well, and am brewing ideas for a few games on the platform.</p>
<p>Do give Engadget&#8217;s article a look!  If you&#8217;re a game developer familiar with XNA, and especially if you&#8217;ve done any Zune HD programming, you should feel right at home developing for Windows Phone!</p>
<p>In fact, you can even get started <em>now </em>by downloading the <a href="http://creators.xna.com/en-US/launchcenter" target="_blank">XNA Game Studio 4.0 Beta</a> from <a href="http://creators.xna.com/" target="_blank">XNA Creator&#8217;s Club Online</a>.  It includes a Windows Phone 7 emulator, so you can get a head-start on development even before devices are available.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.abstrys.com/2010/07/windows-phone-preview-at-engadget/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Porting Sparkles from Zune HD to Windows Phone 7</title>
		<link>http://www.abstrys.com/2010/05/porting-sparkles-from-zune-hd-to-windows-phone-7/</link>
		<comments>http://www.abstrys.com/2010/05/porting-sparkles-from-zune-hd-to-windows-phone-7/#comments</comments>
		<pubDate>Mon, 24 May 2010 19:34:54 +0000</pubDate>
		<dc:creator>Eron</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Windows Phone]]></category>
		<category><![CDATA[accelerometer]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[multitouch]]></category>
		<category><![CDATA[Windows Phone 7]]></category>
		<category><![CDATA[XNA Game Studio 4]]></category>
		<category><![CDATA[Zune HD]]></category>

		<guid isPermaLink="false">http://www.abstrys.com/?p=72</guid>
		<description><![CDATA[InputToy (also known as &#8220;Sparkles&#8221;) started as an application designed to demonstrate programming touch and accelerometer input on the Zune HD with XNA Game Studio 3.1. However, when the XNA Game Studio 4 Community Technical Preview (CTP) was released with support for the upcoming Windows Phone 7, including a built-in emulator, I felt that porting [...]]]></description>
			<content:encoded><![CDATA[<p>InputToy (also known as &#8220;Sparkles&#8221;) started as an application designed to demonstrate programming touch and accelerometer input on the Zune HD with XNA Game Studio 3.1. However, when the XNA Game Studio 4 Community Technical Preview (CTP) was released with support for the upcoming Windows Phone 7, including a built-in emulator, I felt that porting the application to Windows Phone was the next logical step.</p>
<p>This tutorial will provide step-by-step instructions on porting an application from the Zune HD to Windows Phone, using the existing Zune HD Sparkles application (InputToyZuneHD) as an example.  The full source code for that version can be <a href="http://www.abstrys.com/files/source/InputToyZuneHD.zip">downloaded here</a>.</p>
<p><span id="more-72"></span></p>
<p style="padding-left: 30px;"><strong>Important Notes:</strong></p>
<ul>
<li>This article is written about pre-released technology.  It is likely that some of the features, the API, and the products mentioned here will change before final release.  I will attempt to keep this article up-to-date, but no guarantees can be made of the accuracy of this material when compared to the final (future) product.</li>
<li>Since the Windows Phone emulator doesn&#8217;t include accelerometer support, you&#8217;ll need to wait for actual Windows Phone 7 devices to become available to actually see that part of the code in action, but you can certainly work with touch input right now using the emulator.</li>
</ul>
<h2>Prerequisites</h2>
<p>This tutorial assumes that you&#8217;ve already created an application for Zune HD using the steps in the first set of tutorials. If you haven&#8217;t, you may want to at least read through <a href="http://www.abstrys.com/2010/02/making-the-zune-hd-sparkle-with-xna-game-studio-3-1-part-1/" target="_blank">Making the Zune HD Sparkle with XNA Game Studio 3.1 &#8211; Part 1</a> and <a href="http://www.abstrys.com/2010/02/making-the-zune-hd-sparkle-with-xna-game-studio-3-1-part-2/" target="_blank">Part 2</a>.</p>
<p>Before you begin, you&#8217;ll also need the following:</p>
<ul>
<li>The <a href="http://creators.xna.com/en-US/downloads" target="_blank">XNA Game Studio 4 Community Technical Preview</a>.</li>
<li>The <a href="http://www.abstrys.com/files/source/InputToyZuneHD.zip">InputToy code for the Zune HD</a>.  If you have an existing project to work from, you can begin from there.  Otherwise, download the code, unpack it, and follow along.</li>
</ul>
<p>For reference, the full source code for the finished application for  Windows Phone 7 can be <a href="../files/source/InputToyWP7.zip">downloaded  here</a>.</p>
<h2>Converting a Zune HD project to Windows Phone 7</h2>
<p>The first thing you&#8217;ll need to do is create a new Windows Phone game project and copy the source files into it. Call the project <strong>InputToyWP7</strong>. I won&#8217;t go into this process in detail here, since there&#8217;s already an article in the <a href="http://msdn.microsoft.com/en-us/library/bb200104(v=XNAGameStudio.40).aspx" target="_blank">XNA Game Studio 4 documentation</a> about how to do exactly that, called <a href="http://msdn.microsoft.com/en-us/library/ff604985(v=XNAGameStudio.40).aspx" target="_blank">Migrating from Zune to Windows Phone</a>.  It&#8217;s a great guide—trust me, I wrote it!</p>
<p>The source files you will need to copy from the old project are:</p>
<ul>
<li>Game1.cs</li>
<li>Instructions.cs</li>
<li>Menu.cs</li>
</ul>
<p>Copy these into the <em>InputToyWP7</em> directory in your Visual Studio 2010 project.</p>
<p>You&#8217;ll also notice that there&#8217;s an <em>InputToyWP7Content</em> directory in your project, as well. A major difference between the way XNA Game Studio 3.1 and 4.0 behave is that content projects are now full projects alongside the code project, and not in a sub-directory within the code project&#8217;s directory.</p>
<p>From the old project&#8217;s <em>Content</em> directory, copy the following files into the new project&#8217;s <em>InputToyWP7Content</em> directory:</p>
<ul>
<li>btnHelp.png</li>
<li>btnPause.png</li>
<li>btnPlay.png</li>
<li>Flare.png</li>
<li>Instructions.png</li>
</ul>
<p>Once all these files have been added to your projects, you&#8217;ll be ready to proceed with the code modification necessary to get the application running on the WP7 emulator supplied with the XNA GS 4 CTP (wow, three <a href="http://foldoc.org/tla" target="_blank">TLAs</a> in a row!).</p>
<h2>Modifying the game code for Windows Phone</h2>
<h3>Screen dimensions</h3>
<p>The original Zune HD version of this application was written for the Zune HD&#8217;s native screen resolution of 272 x 480.  Windows Phone 7, however, sports a native resolution of 480 x 800.  At some point, the Windows Phone emulator may support the built-in hardware scaling that is planned for the phone, but for now, it supports only the standard 480 x 800 resolution.</p>
<p>In anticipation of being able to set my screen dimensions to be equal to the Zune HD&#8217;s resolution—therefore preserving the original look of my application—I&#8217;m going to set the screen dimensions in a Vector2 that I can easily change in the future.  Add the following member to the <strong>Game1 </strong>class:</p>
<pre><strong><span style="color: #008000;">Vector2 screenDimensions = new Vector2(480, 800);</span></strong></pre>
<p>Now, in the game&#8217;s constructor, we&#8217;ll set the <strong>GraphicsDeviceManager</strong>&#8216;s <strong>PreferredBackBufferWidth</strong> and <strong>PreferredBackBufferHeight</strong> to these dimensions.  We&#8217;ll also set <strong>IsFullScreen</strong> to <em><strong>true</strong></em>.  Add the following code to Game1&#8242;s constructor:</p>
<pre>// Frame rate is 30 fps by default for Windows Phone.
TargetElapsedTime = TimeSpan.FromSeconds(1/30.0);

<strong><span style="color: #008000;">// This makes use of the built-in hardware scaler to work with our original (Zune HD) resolution
graphics.PreferredBackBufferWidth = (int)screenDimensions.X;
graphics.PreferredBackBufferHeight = (int)screenDimensions.Y;

// use the whole screen
graphics.IsFullScreen = true;</span></strong></pre>
<p>Another neat thing that we&#8217;ll get for free is an <em>automatic translation</em> of touchscreen coordinates from WP7&#8242;s native resolution to the resolution that we set for the backbuffer, so we can count on having the same touch coordinates (272 x 480) that we did for Zune HD. This isn&#8217;t an issue now, since we&#8217;re using 480 x 800 resolution, but it&#8217;s nice to know that no additional code changes will be needed when using automatic backbuffer scaling.</p>
<p>Speaking of touch input&#8230; we&#8217;ll now modify our touch input code so it works with GS4.  Thankfully, there won&#8217;t be much to do.</p>
<h3>Changing the touch input code for XNA Game Studio 4</h3>
<p>One difference between XNA GS 3.1 and 4.0 is how the touch input classes are referenced.  In XNA GS 4, they are now inside their own assembly.  To make our old code work with XNA GS 4, we&#8217;ll need to add a new reference to <strong>Microsoft.Xna.Framework.Input.Touch</strong> to the top of <em>Game1.cs</em>:</p>
<pre>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;
<span style="color: #008000;"><strong>using Microsoft.Xna.Framework.Input.Touch;</strong></span>
using Microsoft.Xna.Framework.Media;</pre>
<p>You&#8217;ll also need to make sure that <strong>Microsoft.Xna.Framework.Input.Touch</strong> is  also referenced by your project itself:  Click on the <strong>References </strong>node in  your InputToy source project, and make sure it contains <strong>Microsoft.Xna.Framework.Input.Touch</strong> in the list.  If it doesn&#8217;t, right click the <strong>References </strong>node and  click <strong>Add Reference&#8230;</strong>, then select it from the list and click <strong>OK</strong> to add it to your project.</p>
<p>That&#8217;s it!  Aside from this change, we don&#8217;t need to do anything extra to our code to support touch input on WP7.  As mentioned before, due to the magic of hardware scaling, all our touch input code from the Zune HD version of the application will continue to work fine.</p>
<h3>Changing the accelerometer code for Windows Phone</h3>
<p>This is where things get interesting.  Accelerometers are <em>not</em> supported by XNA GS 4, as they were for Zune HD on XNA GS 3.1.  To work with the accelerometer on Windows Phone, you need to add the <strong>Microsoft.Devices.Sensors</strong> assembly to the project, which is, thankfully, included with the XNA GS 4 CTP you downloaded as a prerequisite.  Add the following line to the using statements at the beginning of Game1.cs (I added it after the <em>using Microsoft.Xna.Framework.Media</em> line):</p>
<pre><strong><span style="color: #008000;">using Microsoft.Devices.Sensors;</span></strong>
</pre>
<p>You&#8217;ll also need to make sure that <strong>Microsoft.Devices.Sensors</strong> is also referenced by your project, as you did for <strong>Microsoft.Xna.Framework.Input.Touch</strong>.</p>
<p><strong>Microsoft.Devices.Sensors</strong> is not an XNA GS assembly—it&#8217;s supplied by Silverlight—and doesn&#8217;t follow the usual programming patterns used with XNA Game Studio.  There&#8217;s no polling for input as there was with <strong>Accelerometer.GetState</strong> in GS 3.1.</p>
<p>Instead, we&#8217;ll be using the <strong>AccelerometerSensor</strong> class in <strong>Microsoft.Devices.Sensors</strong>.  We&#8217;ll also define an event handler that will be called when the <strong>ReadingChanged</strong> event is raised.</p>
<p>First, add the following members to the <strong>Game1</strong> class:</p>
<pre>...
List&lt;Sparkle&gt; sparkles;
Instructions instructions;
Menu menu;
<strong><span style="color: #008000;">bool accelActive = false;
AccelerometerSensor accelSensor;
Vector3 accelReading = new Vector3();</span></strong></pre>
<p>First, we have a boolean value that we&#8217;ll use to keep track of whether the accelerometer is <em>active</em> or not.  Next is a member to hold the AccelerometerSensor object, and finally is a Vector3 that we&#8217;ll use to hold the X, Y, and Z values returned by the accelerometer.</p>
<p>Next, we&#8217;ll add the following code to Game1&#8242;s constructor:</p>
<pre>// This makes use of the built-in hardware scaler to work with our original (Zune HD) resolution
graphics.PreferredBackBufferWidth = (int)screenDimensions.X;
graphics.PreferredBackBufferHeight = (int)screenDimensions.Y;

// use the whole screen
graphics.IsFullScreen = true;

<strong><span style="color: #008000;">accelSensor = new AccelerometerSensor();

// Add the accelerometer event handler to the accelerometer sensor.
accelSensor.ReadingChanged +=
   new EventHandler&lt;AccelerometerReadingAsyncEventArgs&gt;(AccelerometerReadingChanged);

// Start the accelerometer
try
{
   accelSensor.Start();
   accelActive = true;
}
catch (AccelerometerStartFailedException e)
{
   // the accelerometer couldn't be started.  No fun!
   accelActive = false;
}</span></strong></pre>
<p>After creating an instance of the <strong>AccelerometerSensor</strong>, we add the event handler to handle the <strong>ReadingChanged</strong> event.  It will be called <strong>AccelerometerReadingChanged</strong>, and takes an <strong>AccelerometerReadingAsyncEventArgs </strong>argument. We&#8217;ll define this handler in a short while.</p>
<p>For now, notice that we also have to <strong>Start</strong> the accelerometer, and that this call can fail with an <strong>AccelerometerFailedException</strong>.  If it does, we simply set <strong>accelActive</strong> to <strong>false</strong>.</p>
<p>In this case, we&#8217;ll have the accelerometer active during the entire run of the program.  In your own games, you may want to turn off the accelerometer when its not being used.  This can improve performance, since there will be no need to receive or respond to <strong>ReadingChanged</strong>.</p>
<p>Instead, we&#8217;ll just turn off the accelerometer when the program shuts down.  Add the following lines to <strong>UnloadContent</strong>, which is called as the game is exiting:</p>
<pre>protected override void UnloadContent()
{
   // Unload any non ContentManager content here
<span style="color: #008000;"><strong>   // Stop the accelerometer if it's active.
   if (accelActive)
   {
      try
      {
         accelSensor.Stop();
      }
      catch (AccelerometerStopFailedException e)
      {
         // the accelerometer couldn't be stopped now.
      }
   }</strong>
</span>}</pre>
<p>Now, lets revisit the <strong>ReadingChanged </strong>event handler.  We called it <strong>AccelerometerReadingChanged</strong>, but didn&#8217;t actually define the method.  We&#8217;ll do so now.  Add the following method to the Game1 class:</p>
<pre><strong><span style="color: #008000;">public void AccelerometerReadingChanged(object sender, AccelerometerReadingAsyncEventArgs e)
{
   accelReading.X = (float)e.Value.Value.X;
   accelReading.Y = (float)e.Value.Value.Y;
   accelReading.Z = (float)e.Value.Value.Z;
}</span></strong></pre>
<p>There isn&#8217;t much to it: this method simply gets the X, Y, and Z values from the <strong>AccelerometerReadingAsyncEventArgs</strong> object, and saves them in the Vector3 that we defined earlier.</p>
<p>Now, all we need to do is make use of this data.  We actually had code that did this for our Zune HD version of the application, and we&#8217;ll reuse that code.</p>
<p>In Game1&#8242;s Update method, <em>remove </em>the lines that were used to get the accelerometer state, since these are no longer used.  Remove these lines:</p>
<pre><span style="color: #ff0000;"><strong>// grab the accelerometer state.  This will be used for sparkle
// movement.
AccelerometerState accelState = Accelerometer.GetState();</strong></span></pre>
<p>Later in Update, there&#8217;s code that sets the particle speed based on the value in the <strong>accelState</strong> variable.  Find it, and modify the code (modified bits are in <strong><span style="color: #008000;">green</span></strong>, as usual) so that it looks like this:</p>
<pre><strong><span style="color: #008000;">if (accelActive)
{</span></strong>
   // accelerate the sparkle depending on accelerometer
   // action.
   s.speed.X += <span style="color: #008000;"><strong>accelReading.X</strong></span> * ACCELFACTOR;
   s.speed.Y += <span style="color: #008000;"><strong>-accelReading.Y</strong></span> * ACCELFACTOR;

   // move the sparkle based on its speed.
   s.position.X += s.speed.X * etms;
   s.position.Y += s.speed.Y * etms;
   s.rotation += s.speed.Length() * ACCELFACTOR * etms;
<span style="color: #008000;"><strong>}</strong></span></pre>
<p>The only changes we had to make were to make use of the <strong>accelActive </strong>value that tells us the accelerometer has been made active (by calling <strong>Start</strong>), and switching out the <strong>accelState</strong> variable that we removed earlier with our <strong>accelReading</strong> class member.</p>
<p>That&#8217;s it!  Though modifying the accelerometer code was a little more work than it took to modify the touch code, it didn&#8217;t take much more than defining a single event handler and adding the code to instantiate, start, and stop the <strong>AccelerometerSensor</strong>.</p>
<p>You should now be able to build the application and, once you get your hands on a Windows Phone 7 device, be able to see it behave just like it did for Zune HD.  For now, however, you can at least play with the touch portions of the application in the Windows Phone 7 emulator:</p>
<p><a href="http://www.abstrys.com/wp-content/uploads/2010/05/InputToyWP7.png"><img class="aligncenter size-full wp-image-97" title="InputToyWP7" src="http://www.abstrys.com/wp-content/uploads/2010/05/InputToyWP7.png" alt="" width="300" height="522" /></a></p>
<p>As before, please let me know if you have any questions or comments regarding this tutorial, or if you&#8217;d like to see articles covering other subjects.  I hope you enjoyed it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.abstrys.com/2010/05/porting-sparkles-from-zune-hd-to-windows-phone-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

