<?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>Sgt. Conker &#187; Accelerometer</title>
	<atom:link href="http://www.sgtconker.com/category/xna/zunehd/accelerometer/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sgtconker.com</link>
	<description>We are &#34;absolutely fine&#34;</description>
	<lastBuildDate>Thu, 09 Sep 2010 19:48:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Article: Zune HD Accelerometer Basics</title>
		<link>http://www.sgtconker.com/2009/10/zune-hd-accelerometer-basics-placeholder-2/</link>
		<comments>http://www.sgtconker.com/2009/10/zune-hd-accelerometer-basics-placeholder-2/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 13:01:22 +0000</pubDate>
		<dc:creator>Sgt. Conker</dc:creator>
				<category><![CDATA[Accelerometer]]></category>
		<category><![CDATA[Articles]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[ZuneHD]]></category>
		<category><![CDATA[Tiny Engine]]></category>

		<guid isPermaLink="false">http://sgt.conkerjo.com/?p=16</guid>
		<description><![CDATA[Start at the beginning, learn how to use the Accelerometer for the ZuneHD using XNA 3.1]]></description>
			<content:encoded><![CDATA[<h4 style="text-align: center;">by <a href="http://www.conkerjo.com/">Conkerjo</a></h4>
<p><a href="http://www.conkerjo.com/wp-content/uploads/2009/10/mrtiny.png"><img class="alignright" style="display: inline; border: 0px initial initial;" title="mrtiny" src="http://www.conkerjo.com/wp-content/uploads/2009/10/mrtiny_thumb.png" border="0" alt="mrtiny" width="94" height="171" /></a><br />
This article explains the very basics of using the accelerometer on the ZuneHD using XNA 3.1<br />
<span id="more-16"></span></p>
<p><strong>Note</strong><br />
<em>This sample uses a build of the TinyEngine at the time it was written.</em></p>
<p>In this sample I want to show how to move a sprite around using only the Accelerometer for input. We will utilize some of the features of TinyEngine to get us up and running quickly.</p>
<p>XNA Zune Extensions provide a static class called Accelerometer. It provides a GetState method which returns the current state of the Accelerometer as a AccelerometerState type.</p>
<pre class="brush: csharp;">
	public struct AccelerometerState
    {
        public Vector3 Acceleration { get; }

        public bool IsConnected { get; }

        public Matrix GetRotation();
    }
</pre>
<p>Note that this class is not available on Windows and must be wrapped in a #if ZUNE conditional compilation statement if trying to develop a cross-platform game.<br />
The Acceleration is a 3 dimensional value of the direction the Accelerometer is moving at the time.&lt; /br&gt;<br />
The GetRotation gives us a Matrix of the rotation of the device. This is great information for tilting the view to the direction of the device, but that's out of scope for this article.</p>
<p>To use this in our code, as we're only moving a simple 2D sprite, we only need the X &amp; Y of the the Acceleration to apply to the Sprites move method.</p>
<pre class="brush: csharp;">
    AccelerometerState state = Accelerometer.GetState();
    Vector2 accel = new Vector2(state.Acceleration.X, -state.Acceleration.Y);
    this.mrTiny.Move(accel * 100 * elapsed);
</pre>
<p>The Move method here just simply adds the passed in Vector2 to the current Position of the Sprite.</p>
<p>We then add a Clamp check so that the Sprite doesnt go off screen&lt; /br&gt;<br />
Again, TinyEngine provides us with the Bounds of the Screen. With TinyEngine 0,0 is the center of the screen and not the XNA default of top left.</p>
<pre class="brush: csharp;">
    this.mrTiny.PositionX = MathHelper.Clamp(this.mrTiny.PositionX, this.ScreenBounds.Left, this.ScreenBounds.Right);
    this.mrTiny.PositionY = MathHelper.Clamp(this.mrTiny.PositionY, this.ScreenBounds.Top, this.ScreenBounds.Bottom);
</pre>
<p>And there we have it, you can tilt your Zune HD to move around Mr Tiny.</p>
<p>The code is linked just below.</p>
<p><a href="http://www.conkerjo.com/Downloads/TinyEngine.zip" target="_blank">Source Code (Includes Tiny Engine Source)</a></p>
<pre>Conkerjo - www.conkerjo.com - www.twitter.com/conkerjo (Come up with some generic way to show the author)</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sgtconker.com/2009/10/zune-hd-accelerometer-basics-placeholder-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
