<?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; XNA Game Studio Docs &amp; Resources</title>
	<atom:link href="http://www.abstrys.com/tag/xna-game-studio-docs-resources/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>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>Making the Zune HD Sparkle with XNA Game Studio 3.1 &#8211; Part 1</title>
		<link>http://www.abstrys.com/2010/02/making-the-zune-hd-sparkle-with-xna-game-studio-3-1-part-1/</link>
		<comments>http://www.abstrys.com/2010/02/making-the-zune-hd-sparkle-with-xna-game-studio-3-1-part-1/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 08:40:47 +0000</pubDate>
		<dc:creator>Eron</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[accelerometer]]></category>
		<category><![CDATA[input]]></category>
		<category><![CDATA[touch]]></category>
		<category><![CDATA[XNA Game Studio Docs & Resources]]></category>
		<category><![CDATA[Zune HD]]></category>

		<guid isPermaLink="false">http://www.abstrys.com/?p=5</guid>
		<description><![CDATA[Introduction This article explores using XNA Game Studio to access the two primary forms of user input on the Zune HD: the multitouch screen, and the accelerometer. We&#8217;ll do this by building a small demo that allows the user to create sparkles by touching the screen, and to move them around by tilting the device. Over the course [...]]]></description>
			<content:encoded><![CDATA[<div id="Intro">
<h2>Introduction</h2>
<p><img class="alignright" src="http://www.abstrys.com/files/images/InputToy-Part1.png" alt="" width="200" height="264" />This article explores using XNA Game Studio to access the two primary forms of user input on the Zune HD: the multitouch screen, and the accelerometer. We&#8217;ll do this by building a small demo that allows the user to create sparkles by touching the screen, and to move them around by tilting the device.</p>
<p>Over the course of this tutorial, the following subjects will be covered:</p>
<ul>
<li>Multitouch input</li>
<li>Accelerometer input</li>
<li>Animating blended sprites</li>
<li>A simple UI  (in part two)</li>
</ul>
<p>I won&#8217;t be going over how to create a new XNA game project, nor will I describe how to add textures using the Content Pipeline. I assume that the reader has read enough about Game Studio to know how to do these things already. If you haven&#8217;t, I suggest downloading XNA Game Studio (a link is provided below) and going through the <a href="http://msdn.microsoft.com/en-us/library/bb203893.aspx">first tutorial</a> provided in the Game Studio documentation.</p>
<p><span id="more-5"></span></p>
<p>The full sample, including source code, images, and VS2008 project files, can be <a href="http://www.abstrys.com/files/source/InputToyZuneHD.zip">downloaded here</a>. Unless you want to make your own textures while following along with the tutorial, you&#8217;ll at least want to grab the images from the zip archive.</p>
</div>
<div id="Prereqs">
<h2>Prerequisites</h2>
<p><em>This is a Zune HD tutorial</em>: although some parts of the tutorial apply to all XNA Game Studio projects in general, much of the content here will apply only to devices that support both accelerometer and multi-touch input with XNA Game Studio 3.1. At the moment, that list begins and ends with the Zune HD. If you don&#8217;t already have a Zune HD, I&#8217;d recommend borrowing one from a friend, purchasing one, or sticking with Xbox 360 and Windows programming for now.</p>
<p>In addition to having access to a Zune HD, you&#8217;ll need the following software installed:</p>
<ul>
<li><em>Visual Studio 2008</em> &#8211; If you don&#8217;t already have Visual Studio 2008 Professional, you can download <a href="http://www.microsoft.com/express/Downloads/#2008-Visual-CS">Visual Studio 2008 Express edition</a>.</li>
<li><em>XNA Game Studio 3.1</em> &#8211; Available from the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=80782277-D584-42D2-8024-893FCD9D3E82">Microsoft Download Center</a>.</li>
<li><em>XNA Game Studio 3.1 Zune Extensions</em> &#8211; Also available from the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=48F7BA37-8BA7-4D16-8873-0B7F83EF77F9">Microsoft Download Center</a>.</li>
</ul>
<p>As I mentioned in the Introduction, you&#8217;ll also need an understanding of the basics of building an XNA Game Studio application.</p>
</div>
<div id="S1">
<h2>First Steps</h2>
<p>To begin, open Visual Studio 2008 and create a new XNA Game Studio project for Zune. Call it whatever you like. I called this project &#8220;InputToyZuneHD&#8221;.</p>
<p>Then, add some images to the project that we&#8217;ll be using. For now, all you&#8217;ll need is Flare.png, which contains the sparkle image. It looks like this:</p>
<p><img style="background: black;" src="http://www.abstrys.com/files/images/Flare.png" alt="The sparkle image" /><br />
Make sure the Asset Name in the <strong>Properties</strong> pane is &#8220;Flare&#8221; and the <strong>Build Action</strong> is &#8221;Compile&#8221;. We&#8217;re now ready to add some code to the project!</p>
</div>
<div id="AddingSparkles">
<h2>Adding Sparkles</h2>
<p>Open the file &#8220;Game1.cs&#8221; in your project, and right at the top of the <strong>Game1 </strong>class, add the following code:</p>
<pre>public class Game1 : Microsoft.Xna.Framework.Game
{
<span style="color: #008000;">    </span><strong><span style="color: #008000;">static Random random = new Random();
    class Sparkle
    {
        public Vector2 position;
        public Vector2 speed;
        public float rotation; // in radians
        public Color color;
        public long birthtime;

        public Sparkle(float x, float y, long time)
        {
            position = new Vector2(x, y);
            rotation = (float)(random.NextDouble() * 2.0 * Math.PI);
            color = Color.White;
            birthtime = time;
        }</span>
    <span style="color: #008000;">}</span></strong>
...</pre>
<p>First, we&#8217;re just setting up the random number generator, which we&#8217;ll be using when setting up sparkle rotation. Then, we create a class to hold information about each sparkle: its position, speed, rotation, color (which will be used to fade the sparkles), and birthtime (also used for fading).</p>
<p>Then, we&#8217;ll create a constructor that takes a position in screen coordinates (x,y), and a birthtime. We&#8217;re using the same image for all of the sparkles, so there&#8217;s no need to save any image-specific data in the sparkle class.</p>
<p>Notice that we use a random rotation for each sparkle when it&#8217;s created. This helps, since we&#8217;re using the same image, from keeping every sparkle look exactly like the others when it appears. <strong>Random.NextDouble</strong> produces a number between zero and one, so by multiplying it by 2*PI, we can get a random rotation in radians.</p>
<p>Next, we define some constants that will be used to fade sparkles. We&#8217;ll define a maximum lifetime for each sparkle, the maximum number of sparkles allowed on the screen at once, an acceleration factor for sparkle movement, and a factor to control how quickly the sparkles will fade out.</p>
<p>Add this code beneath the definition of the <strong>Sparkle</strong> class:</p>
<pre><span style="color: #008000;"><strong>const int SPARKLELIFE = 4000; // ticks
const int MAXSPARKLES = 100; // maximum number of sparkles, for performance tuning.
const float ACCELFACTOR = 0.01f;
const float FADEFACTOR = 255.0f / SPARKLELIFE;</strong></span></pre>
<p>We&#8217;ll now add a few variables to the class to hold the sparkle data. In <strong>Game1</strong>&#8216;s class data section, where the <em>graphics</em> and <em>spriteBatch </em>members are declared, add new data members called <em>flareImage</em>, <em>flareOffset</em>, and <em>sparkles</em>, as shown:</p>
<pre>GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
<span style="color: #008000;"><strong>Texture2D flareImage;
Vector2 flareOffset;
List&lt;Sparkle&gt; sparkles;</strong></span></pre>
</div>
<div id="LoadingSparkles">
<h2>Loading the Sparkle Image</h2>
<p>There&#8217;s one last thing we&#8217;ll need to do before creating and drawing sparkles, and that&#8217;s loading the sparkle image into the <strong>Texture2D</strong> that we&#8217;ve declared for it.</p>
<p>In <strong>Game1.LoadContent</strong>, add lines to load the flare image and set the flare offset:</p>
<pre>// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);<span style="color: #008000;">
<strong>flareImage = this.Content.Load&lt;Texture2D&gt;("Flare");
flareOffset = new Vector2(
    flareImage.Width * 0.5f, flareImage.Height * 0.5f);</strong></span></pre>
<p>The <em>flareOffset</em> will be used to rotate the sparkles, and is set to the middle of the sparkle texture.</p>
</div>
<div id="CreatingSparkles">
<h2>Creating Sparkles with Touch</h2>
<p>Now, let&#8217;s add some code that uses touch to create sparkles. We&#8217;ll allow the user to touch the screen to create a sparkle, or to create many sparkles by touching multiple points at the same time or by dragging a touch-point.</p>
<p>All of the code in this section will go into <strong>Game1.Update</strong>.</p>
<p>First, we&#8217;ll get the total game time as a <em>long</em>. The <strong>GameTime</strong> structure that&#8217;s passed to <strong>Update</strong> contains a number of members for different timing purposes. Since the sparkle birth-time is something that we&#8217;ll be tracking starting from the beginning of app launch, we&#8217;ll use the <strong>TotalGameTime</strong> member to get a timestamp for sparkle creation. This will allow us to fade the sparkles out over time, and to remove them from the list once they&#8217;ve faded.</p>
<p>To add a sparkle to a location touched on the screen, we&#8217;ll get the <strong>TouchCollection</strong> that contains all of the touch points (represented by the <strong>TouchLocation</strong> structure) that are active (either <strong>Pressed</strong> or <strong>Moved</strong>) this  frame. Iterating through the list and adding sparkes at the <strong>TouchLocation.Position</strong> points is simple, as shown in the following code:</p>
<p>Add the following code to <strong>Update</strong>:</p>
<pre>// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
{
   this.Exit();
}

<strong><span style="color: #008000;">long ttms = (long)gameTime.TotalGameTime.TotalMilliseconds;
<span style="color: #008000;">
</span></span><span style="color: #008000;">// Process touch events
TouchCollection touchCollection = TouchPanel.GetState();
foreach (TouchLocation tl in touchCollection)
{
      // add sparkles based on the touch location
      sparkles.Add(new Sparkle(tl.Position.X,
               tl.Position.Y, ttms));
}</span></strong>
</pre>
<p>We call <strong>TouchPanel.GetState</strong> to get the <strong>TouchCollection</strong>, and then simply iterate through each <strong>TouchLocation</strong>, passing the X and Y locations and the timestamp to <strong>Sparkle</strong>&#8216;s constructor to add a new sparkle to the list.</p>
<p>We now have the code to add sparkles, but there&#8217;s still a problem that we need to solve: if you simply continue to add sparkles, you&#8217;ll soon have many thousands of sparkles on the list, which could really drag down your framerate.</p>
<p>To keep the frame-rate up, we should limit the number of objects that are being updated and drawn each frame. We&#8217;ll impose a limit, represented by <em>MAXSPARKLES</em>, on the number of sparkles that can be in the list at once, by removing sparkles from the beginning of the list if there are too many sparkles in existence. Right after adding a new sparkle, add code to remove the sparkles:</p>
<pre>foreach (TouchLocation tl in touchCollection)
{
   // add sparkles based on the touch location
    sparkles.Add(new Sparkle(tl.Position.X,
             tl.Position.Y, ttms));
<span style="color: #008000;">
<strong>   // if there are too many sparkles, remove from the head.
   if (sparkles.Count &gt; MAXSPARKLES)
   {
      sparkles.RemoveAt(0);
   }</strong></span>
}
</pre>
<p><strong>Note:</strong> The sparkles are removed from the front of the list since these are the oldest sparkles: new sparkles are always added at the end. It would be quite unexpected (in other words, it would seem like a bug) from the user&#8217;s point-of-view if just-created sparkles suddenly disappeared!</p>
</div>
<div id="DrawingSparkles">
<h2>Drawing the Sparkles</h2>
<p>We now have the ability to add sparkles to our world, but unless we draw them on the screen, nobody (but you) will know they exist!</p>
<p>Drawing the sparkles on the screen is a simple matter of iterating through the list we&#8217;ve created, and drawing the Flare image at the location of each sparkle. In <strong>Game1.Draw</strong>, add the following code:</p>
<pre>protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(<span style="color: #008000;"><strong>Color.Black</strong></span>);
<span style="color: #008000;">    <strong>spriteBatch.Begin();
    // draw the sparkles
    foreach(Sparkle s in sparkles)
    {
        // when drawing with a specified origin, the origin affects
        // both the rotation and position parameters.
        spriteBatch.Draw(
            flareImage, s.position, null, s.color, s.rotation,
            flareOffset, 1.0f, SpriteEffects.None, 0);
    }
    spriteBatch.End();
<span style="color: #000000;">...</span></strong></span></pre>
<p>There are a number of <strong>SpriteBatch.Draw</strong> overloads provided in Game Studio, but we&#8217;ll use the version shown above since we&#8217;ll eventually want to change the color and rotation of each sparkle. For now, the color will always be <strong>Color.White </strong>and the rotation will always be zero.</p>
<p>The default template code for an XNA Game Studio game clears the screen to <strong>Color.CornflowerBlue</strong>. While this is a good color to use for debugging purposes, I&#8217;ve designed the sparkle image to look best on a black background. The clear color was changed to <strong>Color.Black</strong> to complement this.</p>
<p>If you&#8217;d like, compile and run the application on your Zune HD. You should be able to draw sparkles on the screen with your fingertips, and watch them disappear as you pass the MAXSPARKLES threshhold.</p>
</div>
<div id="FadingSparkles">
<h2>Fading the Sparkles</h2>
<p>Although the above code removes sparkles from the list if there are too many, it&#8217;s likely that the user will notice sparkles suddenly vanishing from the display. It&#8217;s much nicer if we fade them out, so the user feels that the eventual dissapearance of the sparkle is natural within the design of the world we&#8217;re creating.</p>
<p>To do this, we&#8217;ll make use of the sparkle&#8217;s timestamp, comparing it to the current timestamp to fade the sparkle depending on its age. We&#8217;ll place this code directly after the code, entered in the previous section, that creates the sparkles in the Update method.</p>
<pre><span style="color: #008000;"><strong>// update the sparkles. We count from the end of the list in case
// we need to remove a sparkle (without upsetting the order).
for (int i = sparkles.Count - 1; i &gt;= 0; i--)
{
    Sparkle s = sparkles[i];
    if ((ttms - s.birthtime) &gt; SPARKLELIFE)
    {
        sparkles.RemoveAt(i);
        continue;
    }
    else
    {
        // fade the sparkle a bit, depending on its age.
        s.color.A = (byte)(255.0f - (ttms - s.birthtime) * FADEFACTOR);
    }
}</strong></span></pre>
<p>If the sparkle has passed the end of its lifetime, it&#8217;s removed from the list.</p>
<p>Rebuild and deploy your updated application. You should now see the sparkles fading!</p>
</div>
<div id="AddingMotion">
<h2>Adding Motion with the Accelerometer</h2>
<p>We&#8217;ll now use the Zune HD&#8217;s accelerometer to move the sparkles around on the screen, and add a little speed-based rotation to the sparkles to make them more interesting.</p>
<p>To do this, directly after the total game time calculation, get the elapsed game time in milliseconds, and then get the accelerometer state as shown:</p>
<pre>long ttms = (long)gameTime.TotalGameTime.TotalMilliseconds;

<span style="color: #008000;"><strong>// elapsed time will be used in updating movement
float etms = gameTime.ElapsedGameTime.Milliseconds;
</strong></span>
<span style="color: #008000;"><strong>// grab the accelerometer state.  This will be used for sparkle
// movement.</strong>
</span><span style="color: #008000;"><strong>AccelerometerState accelState = Accelerometer.GetState();</strong></span></pre>
<p>The elapsed game time will be used during sparkle movement. Since I&#8217;m only interested in the elapsed time since the last frame, and I&#8217;m not ever expecting this to be more than a second, I use only <strong>ElapsedGameTime.Milliseconds</strong>.</p>
<p>Next, inside the loop used to update the sparkles, right below the code to fade the sparkles, add the following lines:</p>
<pre>// fade the sparkle a bit, depending on its age.
s.color.A = (byte)(255.0f - (ttms - s.birthtime) * FADEFACTOR);

<span style="color: #008000;"><strong>// accelerate the sparkle depending on accelerometer action.
s.speed.X += accelState.Acceleration.X * ACCELFACTOR;
s.speed.Y += -accelState.Acceleration.Y * 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;</strong></span></pre>
<p>We&#8217;re adding speed to each sparkle based on the current state of the accelerometer, and then updating its position based on its speed. Additionally, we&#8217;re adding a bit of rotation depending on the magnitude of the resulting speed vector. As simple as it is, the effect looks fairly nice.</p>
<p>No changes are needed to the drawing code. Once you rebuild and deploy, you should now see the sparkles moving as you tilt the device.</p>
</div>
<div id="Next">
<h2>What&#8217;s Next?</h2>
<p>The Sparkle application is fairly complete, but for a user who doesn&#8217;t know how it works, it might seem a bit mystifying: unless you touch the screen once it starts, you only see a black screen.</p>
<p>It would be nice to have some instructions pop up as the application starts, and perhaps a way to &#8220;freeze&#8221; the sparkle fading so that the user has more time to play with the sparkles as they slide around the screen.</p>
<p>In the next part of the tutorial, I&#8217;ll add a GUI that consists of an instructions screen and a menu that appears at the bottom of the screen.</p>
<p><strong>Continue with</strong>: <a href="http://www.abstrys.com/2010/02/making-the-zune-hd-sparkle-with-xna-game-studio-3-1-part-2/" target="_self">Making the Zune HD Sparkle with XNA Game Studio 3.1 &#8211; Part 2</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.abstrys.com/2010/02/making-the-zune-hd-sparkle-with-xna-game-studio-3-1-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

