<?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>JSEDLAK &#187; XNA</title>
	<atom:link href="http://jsedlak.org/category/coding/net/xna/feed/" rel="self" type="application/rss+xml" />
	<link>http://jsedlak.org</link>
	<description></description>
	<lastBuildDate>Wed, 01 Sep 2010 00:44:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>FGF 0.1.2.0 Released with Gesture Recognition</title>
		<link>http://jsedlak.org/2010/02/21/fgf-0-1-2-0-released-with-gesture-recognition/</link>
		<comments>http://jsedlak.org/2010/02/21/fgf-0-1-2-0-released-with-gesture-recognition/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 20:27:41 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[FGF]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[Gesture Recognition]]></category>

		<guid isPermaLink="false">http://jsedlak.org/?p=603</guid>
		<description><![CDATA[New to the input engine within the Focused Games Framework is the gesture recognition capabilities, housed in the GestureTracker class. The gesture recognition class currently supports a small subset of the gestures I plan on supporting, but all are useful none-the-less. The included gestures are press, two fingered press, swipe, two fingered swipe, zoom and [...]]]></description>
			<content:encoded><![CDATA[<p>New to the input engine within the Focused Games Framework is the gesture recognition capabilities, housed in the GestureTracker class. The gesture recognition class currently supports a small subset of the gestures I plan on supporting, but all are useful none-the-less. The included gestures are press, two fingered press, swipe, two fingered swipe, zoom and pinch. To use the gesture recognition, instantiate a GestureTracker object, add it to the IGame.Modules list and then listen to its GestureTracked even. You will also need an instance of the InputManager class added to the list of modules.</p>
<p>The following is a small sample taken from one of my games that handles some simple menu swiping (a full sample is on the way).</p>
<p><i>If you do happen to use FGF, I would love to hear what you think! Drop me a line via the <a href="/contact">Contact</a> form or leave a comment here.</i></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p603code2'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6032"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code" id="p603code2"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnGestureTracked<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, GestureArgs args<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// If it wasn't a swipe, we don't care!</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Gesture</span> <span style="color: #008000;">!=</span> Gesture<span style="color: #008000;">.</span><span style="color: #0000FF;">Swipe</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Get the direction of the swipe to determine what way</span>
    <span style="color: #008080; font-style: italic;">// the menus should move</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>args<span style="color: #008000;">.</span><span style="color: #0000FF;">Direction</span><span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// If we are capped at the right side of the menus, return</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>current <span style="color: #008000;">==</span> menus<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// Transition the menus</span>
        menus<span style="color: #008000;">&#91;</span>current<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Transition</span><span style="color: #008000;">&#40;</span>Menu<span style="color: #008000;">.</span><span style="color: #0000FF;">MoveDir</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OffToLeft</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        current<span style="color: #008000;">++;</span>
&nbsp;
        menus<span style="color: #008000;">&#91;</span>current<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Transition</span><span style="color: #008000;">&#40;</span>Menu<span style="color: #008000;">.</span><span style="color: #0000FF;">MoveDir</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnFromRight</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">else</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>current <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
&nbsp;
        menus<span style="color: #008000;">&#91;</span>current<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Transition</span><span style="color: #008000;">&#40;</span>Menu<span style="color: #008000;">.</span><span style="color: #0000FF;">MoveDir</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OffToRight</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        current<span style="color: #008000;">--;</span>
&nbsp;
        menus<span style="color: #008000;">&#91;</span>current<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Transition</span><span style="color: #008000;">&#40;</span>Menu<span style="color: #008000;">.</span><span style="color: #0000FF;">MoveDir</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnFromLeft</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><a href="/wp-content/plugins/download-monitor/download.php?id=23" class="more-link" style="margin-right:5px;float:left;"><img style="padding-top:3px;" src="/images/icons/box.png"/>&nbsp;Download FGF 0.1.2.0 Bin</a>
<div class="Clear"><!--clear--></div>
<p><span id="more-603"></span></p>
<h4>Change Log</h4>
<ul>
<li>Added gesture recognition</li>
<li>Added support for Moved state of Tracs</li>
<li>Changed Collection&lt;T&gt; class to implement interfaces directly rather than inherit from List&lt;T&gt;</li>
<li>Added angle extensions for Vector2 and Vector3</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2010/02/21/fgf-0-1-2-0-released-with-gesture-recognition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FGF: Modules, Not Components</title>
		<link>http://jsedlak.org/2010/01/31/fgf-modules-not-components/</link>
		<comments>http://jsedlak.org/2010/01/31/fgf-modules-not-components/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 15:13:42 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[FGF]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://jsedlak.org/?p=577</guid>
		<description><![CDATA[As you no doubt saw in the writing of the Application class, FGF implements its own version of the XNA Framework’s component classes. The first major reason for doing so is that the builtin component classes require you to pass in a (Framework) Game object through the constructor. While this dependency can be circumvented by [...]]]></description>
			<content:encoded><![CDATA[<p>As you no doubt saw in the writing of the Application class, FGF implements its own version of the XNA Framework’s component classes. The first major reason for doing so is that the builtin component classes require you to pass in a (Framework) Game object through the constructor. While this dependency can be circumvented by implementing the interfaces directly and supplying a manual workaround, the attempt is exactly that: a workaround. The second major reason for my implementation is that by controlling the interfaces and base classes, I can easily support more advanced situations such as the separation between initialization and content loading/unloading. You will see more of this later on when I modify the classes to support asynchronous content loading.</p>
<p>For now, the focus is being put on building a robust base for developers to start working with my framework. Because the goal is to fix the XNA Framework’s implementation, we begin with a simplification of the IGameComponent, IUpdateable and IDrawable interfaces. We combine these three into a single, multi-purpose interface, IModule.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p577code15'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p57715"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code" id="p577code15"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">interface</span> IModule
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">event</span> EventHandler DrawOrderChanged<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">event</span> EventHandler UpdateOrderChanged<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">void</span> Initialize<span style="color: #008000;">&#40;</span>IGame game<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">void</span> Draw<span style="color: #008000;">&#40;</span>GameTime gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span>GameTime gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">int</span> DrawOrder <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #6666cc; font-weight: bold;">int</span> UpdateOrder <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">bool</span> IsVisible <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #6666cc; font-weight: bold;">bool</span> IsEnabled <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #6666cc; font-weight: bold;">bool</span> IsInitialized <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
    IModule Parent <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    ModuleCollection Modules <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><span id="more-577"></span></p>
<p>Although we have carried over many of the properties, methods and events, you should spot some key differences. Specifically the Initialize method now takes a single parameter, IGame, to remove the dependency on the Game class in the framework. Also added are the Parent and Modules properties that allow us to build a tree structure with the modules. This will become crucial to building advanced systems later on.</p>
<p>Before we can build the base class for the IModule interface, we need to build the ModuleCollection class. This class acts as a list of modules but adds added support for calling the specific methods of the IModule interface on each item in the list. This makes management of a large number of modules incredibly simple.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p577code16'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p57716"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p577code16"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ModuleCollection <span style="color: #008000;">:</span> Collection<span style="color: #008000;">&lt;</span>IModule<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> List<span style="color: #008000;">&lt;</span>IModule<span style="color: #008000;">&gt;</span> drawList <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>IModule<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>The class inherits the custom Collection<T> class we wrote earlier to gain access to the events which we will see shortly. Note that an internal list is kept so that we can sort modules for drawing differently. The main collection will keep the modules sorted based on their update order and this way we don’t have to sort each time the modules need to be updated and drawn.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p577code17'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p57717"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p577code17"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">public</span> T GetModule<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">where</span> T <span style="color: #008000;">:</span> <span style="color: #6666cc; font-weight: bold;">class</span>, IModule
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> Count<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #008000;">is</span> T<span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #0600FF; font-weight: bold;">as</span> T<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">default</span><span style="color: #008000;">&#40;</span>T<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>A generic method is supplied here to make the searching and casting of modules easier on the end developer. Next we provide Initialize, Draw and Update methods that do exactly as their names imply.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p577code18'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p57718"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code" id="p577code18"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Initialize<span style="color: #008000;">&#40;</span>IGame game<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>IsInitialized<span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
&nbsp;
        Game <span style="color: #008000;">=</span> game<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> Count<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsInitialized</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Initialize</span><span style="color: #008000;">&#40;</span>game<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        IsInitialized <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Draw<span style="color: #008000;">&#40;</span>GameTime gameTime<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> drawList<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>drawList<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsVisible</span><span style="color: #008000;">&#41;</span>
                drawList<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span>GameTime gameTime<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> Count<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsEnabled</span><span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>When an item is added to the list, we have to do a few things. First we have to make sure it is a module. We have to add some event handlers to its events and then we have to add it to the lists and sort each one. If the main list has been initialized, we have to initialize the module itself.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p577code19'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p57719"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code" id="p577code19"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnItemAdded<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, CollectionChangedEventArgs args<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        IModule module <span style="color: #008000;">=</span> args<span style="color: #008000;">.</span><span style="color: #0000FF;">Item</span> <span style="color: #0600FF; font-weight: bold;">as</span> IModule<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>module <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
&nbsp;
        module<span style="color: #008000;">.</span><span style="color: #0000FF;">DrawOrderChanged</span> <span style="color: #008000;">+=</span> OnModuleDrawOrderChanged<span style="color: #008000;">;</span>
        module<span style="color: #008000;">.</span><span style="color: #0000FF;">UpdateOrderChanged</span> <span style="color: #008000;">+=</span> OnModuleUpdateOrderChanged<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>IsInitialized <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">!</span>module<span style="color: #008000;">.</span><span style="color: #0000FF;">IsInitialized</span><span style="color: #008000;">&#41;</span>
            module<span style="color: #008000;">.</span><span style="color: #0000FF;">Initialize</span><span style="color: #008000;">&#40;</span>Game<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        drawList<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>module<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        drawList<span style="color: #008000;">.</span><span style="color: #0000FF;">Sort</span><span style="color: #008000;">&#40;</span>DrawOrderComparer<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Default</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        Sort<span style="color: #008000;">&#40;</span>UpdateOrderComparer<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Default</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnItemAdded</span><span style="color: #008000;">&#40;</span>sender, args<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnModuleUpdateOrderChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Sort<span style="color: #008000;">&#40;</span>UpdateOrderComparer<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Default</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnModuleDrawOrderChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        drawList<span style="color: #008000;">.</span><span style="color: #0000FF;">Sort</span><span style="color: #008000;">&#40;</span>DrawOrderComparer<span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Default</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Later, when a module is removed, we have to remove those event handlers and remove it from any internal list. Essentially this is the reverse process of adding, except that we do not have to resort the lists.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p577code20'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p57720"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p577code20"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnItemRemoved<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, CollectionChangedEventArgs args<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        IModule module <span style="color: #008000;">=</span> args<span style="color: #008000;">.</span><span style="color: #0000FF;">Item</span> <span style="color: #0600FF; font-weight: bold;">as</span> IModule<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>module <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
&nbsp;
        module<span style="color: #008000;">.</span><span style="color: #0000FF;">DrawOrderChanged</span> <span style="color: #008000;">-=</span> OnModuleDrawOrderChanged<span style="color: #008000;">;</span>
        module<span style="color: #008000;">.</span><span style="color: #0000FF;">UpdateOrderChanged</span> <span style="color: #008000;">-=</span> OnModuleUpdateOrderChanged<span style="color: #008000;">;</span>
&nbsp;
        drawList<span style="color: #008000;">.</span><span style="color: #0000FF;">Remove</span><span style="color: #008000;">&#40;</span>module<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OnItemRemoved</span><span style="color: #008000;">&#40;</span>sender, args<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And finally some properties to close off the class.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p577code21'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p57721"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p577code21"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">protected</span> IGame Game <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsInitialized <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Now that we have the ModuleCollection class, we can write the Module (base) class itself. The class is a basic implementation of the IModule interface and inherits the NotifyPropertyChangedBase class to support some advanced data &#038; binding situations.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p577code22'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p57722"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code" id="p577code22"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Module <span style="color: #008000;">:</span> NotifyPropertyChangedBase, IModule
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> drawOrder <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> updateOrder <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">bool</span> isVisible <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">bool</span> isEnabled <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">private</span> IModule parent <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">event</span> EventHandler DrawOrderChanged<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">event</span> EventHandler UpdateOrderChanged<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> Module<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Modules <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ModuleCollection<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        Modules<span style="color: #008000;">.</span><span style="color: #0000FF;">ItemAdded</span> <span style="color: #008000;">+=</span> OnModuleAdded<span style="color: #008000;">;</span>
        Modules<span style="color: #008000;">.</span><span style="color: #0000FF;">ItemRemoved</span> <span style="color: #008000;">+=</span> OnModuleRemoved<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>When the DrawOrder or UpdateOrder properties are changed, we need to invoke their respective events.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p577code23'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p57723"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p577code23"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnDrawOrderChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs args<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>DrawOrderChanged <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> DrawOrderChanged<span style="color: #008000;">.</span><span style="color: #0000FF;">Invoke</span><span style="color: #008000;">&#40;</span>sender, args<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnUpdateOrderChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs args<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>UpdateOrderChanged <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> UpdateOrderChanged<span style="color: #008000;">.</span><span style="color: #0000FF;">Invoke</span><span style="color: #008000;">&#40;</span>sender, args<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>When a child module is added, we have to set its parent. Similarly when a module is removed, we have to unset the parent (if it hasn’t been manually changed).</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p577code24'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p57724"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p577code24"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnModuleAdded<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, CollectionChangedEventArgs args<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        IModule module <span style="color: #008000;">=</span> args<span style="color: #008000;">.</span><span style="color: #0000FF;">Item</span> <span style="color: #0600FF; font-weight: bold;">as</span> IModule<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>module <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
&nbsp;
        module<span style="color: #008000;">.</span><span style="color: #0000FF;">Parent</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnModuleRemoved<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, CollectionChangedEventArgs args<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        IModule module <span style="color: #008000;">=</span> args<span style="color: #008000;">.</span><span style="color: #0000FF;">Item</span> <span style="color: #0600FF; font-weight: bold;">as</span> IModule<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>module <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// First we check to ensure that the developer</span>
        <span style="color: #008080; font-style: italic;">// hasn't set the parent manually to some other</span>
        <span style="color: #008080; font-style: italic;">// object before we remove ourselves as parent.</span>
        <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>module<span style="color: #008000;">.</span><span style="color: #0000FF;">Parent</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#41;</span>
            module<span style="color: #008000;">.</span><span style="color: #0000FF;">Parent</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The Initialize, Draw and Update methods are incredibly straight forward. For the most part the respective method is called on the list of child modules.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p577code25'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p57725"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p577code25"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> Initialize<span style="color: #008000;">&#40;</span>IGame game<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Game <span style="color: #008000;">=</span> game<span style="color: #008000;">;</span>
&nbsp;
        Modules<span style="color: #008000;">.</span><span style="color: #0000FF;">Initialize</span><span style="color: #008000;">&#40;</span>game<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        IsInitialized <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> Draw<span style="color: #008000;">&#40;</span>GameTime gameTime<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Modules<span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> Update<span style="color: #008000;">&#40;</span>GameTime gameTime<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Modules<span style="color: #008000;">.</span><span style="color: #0000FF;">Update</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And last but not least the properties.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p577code26'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p57726"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code" id="p577code26"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> DrawOrder
    <span style="color: #008000;">&#123;</span>
        get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> drawOrder<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        set
        <span style="color: #008000;">&#123;</span>
            drawOrder <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
&nbsp;
            OnDrawOrderChanged<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, EventArgs<span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">int</span> UpdateOrder
    <span style="color: #008000;">&#123;</span>
        get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> updateOrder<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        set
        <span style="color: #008000;">&#123;</span>
            updateOrder <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
&nbsp;
            OnUpdateOrderChanged<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, EventArgs<span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsVisible
    <span style="color: #008000;">&#123;</span>
        get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> isVisible<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        set <span style="color: #008000;">&#123;</span> isVisible <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsEnabled
    <span style="color: #008000;">&#123;</span>
        get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> isEnabled<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        set <span style="color: #008000;">&#123;</span> isEnabled <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> IModule Parent
    <span style="color: #008000;">&#123;</span>
        get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> parent<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        set <span style="color: #008000;">&#123;</span> parent <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsInitialized <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">protected</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> ModuleCollection Modules <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">protected</span> IGame Game <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Now that we have our base module class, we can start creating games without using the builtin component classes!</p>
]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2010/01/31/fgf-modules-not-components/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FGF: Oriented Drawing</title>
		<link>http://jsedlak.org/2010/01/12/fgf-oriented-drawing/</link>
		<comments>http://jsedlak.org/2010/01/12/fgf-oriented-drawing/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 11:40:57 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[FGF]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[Zune HD]]></category>

		<guid isPermaLink="false">http://jso.fg.com/?p=532</guid>
		<description><![CDATA[After you&#8217;ve read about the Display Orientation features of FGF, a natural question to ask is &#8220;How do I draw and take input with a rotated display?&#8221; Fortunately FGF has some methods to help in this department that sit alongside the rotation methods and properties in the Application class. Application.OrientedDisplaySize If you need to draw [...]]]></description>
			<content:encoded><![CDATA[<p>After you&#8217;ve read about the <a href="/2010/01/11/fgf-display-orientation-on-the-zune-hd/">Display Orientation</a> features of FGF, a natural question to ask is &#8220;How do I draw and take input with a rotated display?&#8221; Fortunately FGF has some methods to help in this department that sit alongside the rotation methods and properties in the Application class.</p>
<h4>Application.OrientedDisplaySize</h4>
<p>If you need to draw something relative to the size of the screen, use the <i>OrientedDisplaySize</i> property of the Application class. This property differs from <i>DisplaySize</i>, which is used to change the actual size of the display, in that <i>OrientatedDisplaySize</i> reacts to the selected rotation of the display, set with the <i>DisplayOrientation</i> property.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p532code28'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p53228"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p532code28"><pre class="csharp" style="font-family:monospace;">DisplaySize <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Vector2<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">272</span>, <span style="color: #FF0000;">480</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
DisplayOrientation <span style="color: #008000;">=</span> DisplayOrientation<span style="color: #008000;">.</span><span style="color: #0000FF;">Rotated</span><span style="color: #008000;">;</span>
&nbsp;
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>OrientedDisplaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>Because the display is set to be rotated (landscape on the Zune HD), the above code will actually print out a display size of (480, 272) rather than the standard (272, 480) size.</p>
<p><span id="more-532"></span></p>
<h4>Application.DisplayOrientation</h4>
<p>Get or set the orientation of the display. Setting this value to standard will set landscape mode on the PC and portrait mode on the Zune HD. At the time of writing this article, the PC/Xbox360 version of FGF does not support rotating the display but setting the orientation to Rotated on the Zune HD will enable landscape mode.</p>
<h4>Application.DisplayRotation</h4>
<p>You can view the rotation value being used to render the global render target through this property. Note that this property is used in conjunction with the <i>DisplaySpriteEffects</i> and <i>DisplayOrientation</i> properties and cannot be set manually.</p>
<h4>DisplaySpriteEffects</h4>
<p>You can view the sprite effectsbeing used to render the global render target through this property. Note that this property is used in conjunction with the <i>DisplayRotation</i> and <i>DisplayOrientation</i> properties and cannot be set manually.</p>
<h4>Application.DisplaySize</h4>
<p>The standard size of the display is given by the <i>DisplaySize</i> property. Set this property to change the size of the display at any time.</p>
<h4>Application.ScreenToObject(Vector2)</h4>
<p>The <i>ScreenToObject</i> method is used to translate screen space coordinates into object space coordinates. The major use of this method is to translate touch panel positions into object space where they can be used for object selection.</p>
<h4>Application.ObjectToScreen(Vector2)</h4>
<p>Opposite of the <i>ScreenToObject</i> method, <i>ObjectToScreen</i> converts object space coordinates to screen space coordinates. Note that the resulting coordinates are <b>not</b> to be used for drawing in an oriented application; objects will automatically be rotated and positioned correctly via the global render target.</p>
]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2010/01/12/fgf-oriented-drawing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FGF: Display Orientation on the Zune HD</title>
		<link>http://jsedlak.org/2010/01/11/fgf-display-orientation-on-the-zune-hd/</link>
		<comments>http://jsedlak.org/2010/01/11/fgf-display-orientation-on-the-zune-hd/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 10:38:58 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[FGF]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[Zune HD]]></category>

		<guid isPermaLink="false">http://jso.fg.com/?p=515</guid>
		<description><![CDATA[New in the Focused Games Framework is the support for rotating and resizing the display on the fly. The main reason for this functionality is for mobile platforms like the Zune HD that support games in a landscape mode as well as a portrait mode. Supporting either in your game is made easy with FGF-you [...]]]></description>
			<content:encoded><![CDATA[<p>New in the <a href="/fgf">Focused Games Framework</a> is the support for rotating and resizing the display on the fly. The main reason for this functionality is for mobile platforms like the Zune HD that support games in a landscape mode as well as a portrait mode. Supporting either in your game is made easy with FGF-you just need to know the right properties. In the standard display mode, the Zune HD has a display resolution of 272 pixels by 480 pixels. In landscape mode those two measurements are switched: 480 pixels by 272 pixels. While it is important to know the standard resolution, mucking about with a render target and backbuffer size is no longer necessary.
<p>The one hitch? Your game class needs to inherit from FocusedGames.Xna.Application instead of Microsoft&#8217;s Game class. The following code block sets a Zune HD game up for landscape rendering.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p515code30'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p51530"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p515code30"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Game1 <span style="color: #008000;">:</span> Application
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> Game1<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Set the display size and the rotation</span>
        DisplaySize <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Vector2<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">272</span>, <span style="color: #FF0000;">480</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        DisplayOrientation <span style="color: #008000;">=</span> DisplayOrientation<span style="color: #008000;">.</span><span style="color: #0000FF;">Rotated</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// ...</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Note that to keep the device in portrait mode, you don&#8217;t need to change the value of <i>DisplayOrientation</i> but setting the <i>DisplaySize</i> property to the standard value is a good idea. Happy landscaping!</p>
]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2010/01/11/fgf-display-orientation-on-the-zune-hd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FGF: It&#8217;s All About Abstraction</title>
		<link>http://jsedlak.org/2009/11/16/fgf-its-all-about-abstraction/</link>
		<comments>http://jsedlak.org/2009/11/16/fgf-its-all-about-abstraction/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 15:41:58 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[FGF]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://jsedlak.com/?p=256</guid>
		<description><![CDATA[One of the major themes present in the design of FGF is abstraction of functionality from its implementation. The major reason for this is because one of the major goals of FGF is to provide functionality without forcing developers into a corner. The idea is if the base of the framework is modular and open, [...]]]></description>
			<content:encoded><![CDATA[<p>One of the major themes present in the design of FGF is abstraction of functionality from its implementation. The major reason for this is because one of the major goals of FGF is to provide functionality without forcing developers into a corner. The idea is if the base of the framework is modular and open, the rest of the framework will fall into place very easily. So I begin the implementation of FGF by <span style="text-decoration:line-through;">fixing</span>improving the XNA Framework&#8217;s Game class with an abstraction of its functionality. The reason for which will become apparent when the component classes are improved at a later time.</p>
<p>The important question to ask here is what can a game do? We can run a game, and exit a game but also add and remove components and services. Thus the IGame interface is born (within the FocusedGames.Xna project):</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p256code45'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25645"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code" id="p256code45"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> FocusedGames<span style="color: #008000;">.</span><span style="color: #0000FF;">Xna</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">interface</span> IGame
    <span style="color: #008000;">&#123;</span>
        <span style="color: #6666cc; font-weight: bold;">void</span> Run<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #6666cc; font-weight: bold;">void</span> Exit<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        Vector2 ObjectToScreen<span style="color: #008000;">&#40;</span>Vector2 objectVector<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        Vector2 ScreenToObject<span style="color: #008000;">&#40;</span>Vector2 screenVector<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        GraphicsDeviceManager DeviceManager <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        DisplayOrientation DisplayOrientation <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        Vector2 DisplaySize <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #6666cc; font-weight: bold;">bool</span> IsLoaded <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #6666cc; font-weight: bold;">float</span> TargetFrameRate <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        ModuleCollection Modules <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><span id="more-256"></span></p>
<p>It should be immediately obvious that there are elements to this code that do not compile. I have added extra functionality due to the foresight of working with the Zune HD device and its re-orientating capabilities. Mainly the IGame interface (and any class that implements it) needs to provide a mechanism for dealing with how the screen and the objects within that screen are presented to the user. As for the last element, <i>Modules</i>, don&#8217;t worry about that for now as it will be covered in the next section.</p>
<p>Before implementing the IGame interface, the DisplayOrientation enumeration needs to be defined. You may have better terminology for all the options, I went with what came to my head initially and admit they aren&#8217;t the most descriptive choices. Remember that they have to describe the orientation on all the platforms and that the Zune HD&#8217;s landscape mode is much like the PC&#8217;s standard mode in terms of aspect ratio.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p256code46'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25646"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code" id="p256code46"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">namespace</span> FocusedGames<span style="color: #008000;">.</span><span style="color: #0000FF;">Xna</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Represents the orientation of the display.</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">enum</span> DisplayOrientation <span style="color: #008000;">:</span> <span style="color: #6666cc; font-weight: bold;">byte</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Represents the standard orientation of the display. For Zune and Zune HD this is portrait mode.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        Standard <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Represents a 180 degree flip of the standard orientation.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        Flipped <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>,
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Represents a 90 degree rotation of the standard orientation. For the Zune and Zune HD this is landscape mode.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        Rotated <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span>,
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Represents a -90 degree rotation of the standard orientation.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        ReverseRotated <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>For now a dummy ModuleCollection class will do:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p256code47'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25647"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p256code47"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">namespace</span> FocusedGames<span style="color: #008000;">.</span><span style="color: #0000FF;">Xna</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ModuleCollection
    <span style="color: #008000;">&#123;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Finally we are ready to start implementing the IGame interface in a base class called Application so as not to confuse it with the XNA Framework&#8217;s Game class.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p256code48'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25648"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p256code48"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Xna.Framework.Graphics</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> FocusedGames<span style="color: #008000;">.</span><span style="color: #0000FF;">Xna</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Application <span style="color: #008000;">:</span> Game, IGame
    <span style="color: #008000;">&#123;</span></pre></td></tr></table></div>

<p>The implementation will need a certain number of members to deal with the orientation of the screen. Specifically, a render target will be used to draw everything and then rotated it rather than rotating everything as they are drawn. I have found this makes for simpler code for end developers because rotations can get complicated fast.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p256code49'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25649"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p256code49"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">private</span> DisplayOrientation displayOrientation<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">float</span> displayRotation <span style="color: #008000;">=</span> 0f<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> SpriteEffects displaySpriteEffects <span style="color: #008000;">=</span> SpriteEffects<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> Vector2 orientedDisplaySize <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Vector2<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">800</span>, <span style="color: #FF0000;">600</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> Vector2 displaySize <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Vector2<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">800</span>, <span style="color: #FF0000;">600</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> SpriteBatch spriteBatch<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">private</span> RenderTarget2D renderTarget<span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>Next comes the default constructor for the class which simply initializes several of the members for use later on. Here is where the basic defaults of any game are defined and you&#8217;ll note the Zune specific code for &quot;saving&quot; battery life.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p256code50'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25650"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p256code50"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">public</span> Application<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            Modules <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ModuleCollection<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            DeviceManager <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> GraphicsDeviceManager<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            ClearColor <span style="color: #008000;">=</span> Color<span style="color: #008000;">.</span><span style="color: #0000FF;">Black</span><span style="color: #008000;">;</span>
            DisplayOrientation <span style="color: #008000;">=</span> DisplayOrientation<span style="color: #008000;">.</span><span style="color: #0000FF;">Standard</span><span style="color: #008000;">;</span>
&nbsp;
            Content<span style="color: #008000;">.</span><span style="color: #0000FF;">RootDirectory</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Content&quot;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080;">#if ZUNE</span>
            <span style="color: #008080; font-style: italic;">// Frame rate is 30 fps by default for Zune.</span>
            TargetElapsedTime <span style="color: #008000;">=</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">FromSeconds</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">30.0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080;">#endif</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The implementation needs to load some content, set the display size up and then handle when the content needs to be unloaded. To do this the virtual methods provided by the XNA Framework work wonders. Just remember that when inheriting this class in the XNA game template to include calls to the base methods both in LoadContent and UnloadContent (they aren&#8217;t included by default &#8211; ugh!).</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p256code51'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25651"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code" id="p256code51"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> LoadContent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            spriteBatch <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SpriteBatch<span style="color: #008000;">&#40;</span>GraphicsDevice<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            SetDisplaySize<span style="color: #008000;">&#40;</span>displaySize<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            ResetRenderTarget<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LoadContent</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            IsLoaded <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> UnloadContent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>spriteBatch <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">!</span>spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">IsDisposed</span><span style="color: #008000;">&#41;</span>
                spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Dispose</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UnloadContent</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            IsLoaded <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And now for the creation of the workhorse functions that maintain the orientation and display size and render target all in perfect harmony! The first one up is a function that is called to change the orientation of the display at any time. There are a couple ways of going about this; I have found using the sprite effects to be simple and effective. It is important to note that at the end of the function the render target is reset if the game has been loaded. If you fail to do this, things will get funky!</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p256code52'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25652"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code" id="p256code52"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> SetDisplayOrientation<span style="color: #008000;">&#40;</span>DisplayOrientation newOrientation<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// Removed so this method can act as a reset as well</span>
            <span style="color: #008080; font-style: italic;">// if (newOrientation == displayOrientation) return;</span>
&nbsp;
            displayOrientation <span style="color: #008000;">=</span> newOrientation<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// TODO: Handle orientations</span>
            <span style="color: #0600FF; font-weight: bold;">switch</span> <span style="color: #008000;">&#40;</span>displayOrientation<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">case</span> DisplayOrientation<span style="color: #008000;">.</span><span style="color: #0000FF;">Standard</span><span style="color: #008000;">:</span>
                    orientedDisplaySize <span style="color: #008000;">=</span> displaySize<span style="color: #008000;">;</span>
                    displayRotation <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
                    displaySpriteEffects <span style="color: #008000;">=</span> SpriteEffects<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">case</span> DisplayOrientation<span style="color: #008000;">.</span><span style="color: #0000FF;">Flipped</span><span style="color: #008000;">:</span>
                    orientedDisplaySize <span style="color: #008000;">=</span> displaySize<span style="color: #008000;">;</span>
                    displayRotation <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
                    displaySpriteEffects <span style="color: #008000;">=</span> SpriteEffects<span style="color: #008000;">.</span><span style="color: #0000FF;">FlipVertically</span> <span style="color: #008000;">|</span> SpriteEffects<span style="color: #008000;">.</span><span style="color: #0000FF;">FlipHorizontally</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">case</span> DisplayOrientation<span style="color: #008000;">.</span><span style="color: #0000FF;">Rotated</span><span style="color: #008000;">:</span>
                    orientedDisplaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">=</span> displaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">;</span>
                    orientedDisplaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span> <span style="color: #008000;">=</span> displaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">;</span>
                    displayRotation <span style="color: #008000;">=</span> MathHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">PiOver2</span><span style="color: #008000;">;</span>
                    displaySpriteEffects <span style="color: #008000;">=</span> SpriteEffects<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">case</span> DisplayOrientation<span style="color: #008000;">.</span><span style="color: #0000FF;">ReverseRotated</span><span style="color: #008000;">:</span>
                    orientedDisplaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">=</span> displaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">;</span>
                    orientedDisplaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span> <span style="color: #008000;">=</span> displaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">;</span>
                    displayRotation <span style="color: #008000;">=</span> MathHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">PiOver2</span><span style="color: #008000;">;</span>
                    displaySpriteEffects <span style="color: #008000;">=</span> SpriteEffects<span style="color: #008000;">.</span><span style="color: #0000FF;">FlipVertically</span> <span style="color: #008000;">|</span> SpriteEffects<span style="color: #008000;">.</span><span style="color: #0000FF;">FlipHorizontally</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">//SpriteEffects.FlipHorizontally;</span>
                    <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span><span style="color: #008000;">&#40;</span>IsLoaded<span style="color: #008000;">&#41;</span>
                ResetRenderTarget<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The following method changes the display size of the screen and calls the previous method, SetDisplayOrientation, because as the screen size is changed, everything else is affected.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p256code53'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25653"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p256code53"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> SetDisplaySize<span style="color: #008000;">&#40;</span>Vector2 newSize<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// Removed so this method can act as a reset as well</span>
            <span style="color: #008080; font-style: italic;">// if (newSize == displaySize) return;</span>
&nbsp;
            displaySize <span style="color: #008000;">=</span> newSize<span style="color: #008000;">;</span>
            orientedDisplaySize <span style="color: #008000;">=</span> newSize<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Reset the backbuffer</span>
            DeviceManager<span style="color: #008000;">.</span><span style="color: #0000FF;">PreferredBackBufferWidth</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>displaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">;</span>
            DeviceManager<span style="color: #008000;">.</span><span style="color: #0000FF;">PreferredBackBufferHeight</span> <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>displaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// If we already loaded, apply the changed</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>IsLoaded<span style="color: #008000;">&#41;</span>
                DeviceManager<span style="color: #008000;">.</span><span style="color: #0000FF;">ApplyChanges</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Reset the orientation details</span>
            SetDisplayOrientation<span style="color: #008000;">&#40;</span>displayOrientation<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And finally a method that resets the render target. In the future, the stub for Windows / Xbox 360 must be filled in with a robust RT creation method.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p256code54'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25654"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p256code54"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> ResetRenderTarget<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
<span style="color: #008080;">#if ZUNE</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>renderTarget <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">!</span>renderTarget<span style="color: #008000;">.</span><span style="color: #0000FF;">IsDisposed</span><span style="color: #008000;">&#41;</span>
                renderTarget<span style="color: #008000;">.</span><span style="color: #0000FF;">Dispose</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            renderTarget <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> RenderTarget2D<span style="color: #008000;">&#40;</span>GraphicsDevice, <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>orientedDisplaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span>, <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>orientedDisplaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span>, <span style="color: #FF0000;">1</span>, SurfaceFormat<span style="color: #008000;">.</span><span style="color: #0000FF;">Color</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080;">#else</span>
            <span style="color: #008080; font-style: italic;">// TODO: Do some RT work here for Windows / Xbox 360</span>
<span style="color: #008080;">#endif</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>But really that is only half of the implementation! Now that we have the members setup for drawing an orientated screen, the drawing actually has to happen. This code comes your way from Nick Gravelyn with some minor modifications. The first method, ClearGraphicsDevice, is provided as a virtual member because it should be changed by end-developers when complex clears need to occur. This is done in lieu of many more options and fields on the IGame interface.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p256code55'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25655"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p256code55"><pre class="csharp" style="font-family:monospace;">        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Clears the GraphicsDevice.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> ClearGraphicsDevice<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">Clear</span><span style="color: #008000;">&#40;</span>ClearColor<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>In the BeginDraw method, the device needs to be cleared and the render target needs to be setup in some cases. In other cases, clearing the device is enough and the function is short circuited.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p256code56'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25656"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code" id="p256code56"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">bool</span> BeginDraw<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BeginDraw</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>DisplayOrientation <span style="color: #008000;">==</span> DisplayOrientation<span style="color: #008000;">.</span><span style="color: #0000FF;">Standard</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    ClearGraphicsDevice<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>renderTarget <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> renderTarget<span style="color: #008000;">.</span><span style="color: #0000FF;">IsDisposed</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    ClearGraphicsDevice<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
&nbsp;
                GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">SetRenderTarget</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, renderTarget<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                ClearGraphicsDevice<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">Viewport</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Viewport
                <span style="color: #008000;">&#123;</span>
                    X <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,
                    Y <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,
                    Width <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>orientedDisplaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span>,
                    Height <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>orientedDisplaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span>,
                    MinDepth <span style="color: #008000;">=</span> GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">Viewport</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MinDepth</span>,
                    MaxDepth <span style="color: #008000;">=</span> GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">Viewport</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MaxDepth</span>
                <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And last but certainly not least, the EndDraw and supporting methods need to clean up, present the render target and then draw any overlays before presenting to the screen. Here is where the real rotation magic occurs.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p256code57'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25657"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
</pre></td><td class="code" id="p256code57"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> EndDraw<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>IsLoaded<span style="color: #008000;">&#41;</span>
                <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>DisplayOrientation <span style="color: #008000;">==</span> DisplayOrientation<span style="color: #008000;">.</span><span style="color: #0000FF;">Standard</span> <span style="color: #008000;">||</span>
                <span style="color: #008000;">&#40;</span>renderTarget <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">null</span> <span style="color: #008000;">||</span> renderTarget<span style="color: #008000;">.</span><span style="color: #0000FF;">IsDisposed</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">//base.EndDraw();</span>
                FinalizeDraw<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">SetRenderTarget</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">Viewport</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Viewport
            <span style="color: #008000;">&#123;</span>
                X <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,
                Y <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,
                Width <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>displaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span>,
                Height <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>displaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span>,
                MinDepth <span style="color: #008000;">=</span> GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">Viewport</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MinDepth</span>,
                MaxDepth <span style="color: #008000;">=</span> GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">Viewport</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MaxDepth</span>
            <span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
            spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Begin</span><span style="color: #008000;">&#40;</span>SpriteBlendMode<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span>, SpriteSortMode<span style="color: #008000;">.</span><span style="color: #0000FF;">Immediate</span>, SaveStateMode<span style="color: #008000;">.</span><span style="color: #0000FF;">SaveState</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span>
                renderTarget<span style="color: #008000;">.</span><span style="color: #0000FF;">GetTexture</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>,
                displaySize <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
                <span style="color: #0600FF; font-weight: bold;">null</span>,
                Color<span style="color: #008000;">.</span><span style="color: #0000FF;">White</span>,
                DisplayRotation,
                orientedDisplaySize <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span>,
                1f,
                DisplaySpriteEffects,
                <span style="color: #FF0000;">0</span>
            <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">End</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">//base.EndDraw();</span>
            FinalizeDraw<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> FinalizeDraw<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            DrawOverlay<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">EndDraw</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Draw's unrotated graphics.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">virtual</span> <span style="color: #6666cc; font-weight: bold;">void</span> DrawOverlay<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And before we can really call this implementation done (for now anyways), the various properties used need to be defined. These are given to you a la shotgun because they are straight forward and self explanatory.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p256code58'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25658"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
</pre></td><td class="code" id="p256code58"><pre class="csharp" style="font-family:monospace;">        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets screen coordinates from object coordinates.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;objectVector&quot;&gt;The object's coordinates.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;Coordinates in screen space.&lt;/returns&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> Vector2 ObjectToScreen<span style="color: #008000;">&#40;</span>Vector2 objectVector<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> Vector2<span style="color: #008000;">&#40;</span>displaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">-</span> objectVector<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span>, objectVector<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets object coordinates from screen coordinates.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;screenVector&quot;&gt;The coordinates in screen space.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;Coordinates in object space.&lt;/returns&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> Vector2 ScreenToObject<span style="color: #008000;">&#40;</span>Vector2 screenVector<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> Vector2<span style="color: #008000;">&#40;</span>screenVector<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span>, displaySize<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span> <span style="color: #008000;">-</span> screenVector<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> GraphicsDeviceManager DeviceManager <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets or Sets the orientation of the display.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> DisplayOrientation DisplayOrientation
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> displayOrientation<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> SetDisplayOrientation<span style="color: #008000;">&#40;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets or Sets the size of the display.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> Vector2 DisplaySize
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> displaySize<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set <span style="color: #008000;">&#123;</span> SetDisplaySize<span style="color: #008000;">&#40;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets the rotation of the display.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;seealso cref=&quot;DisplaySpriteEffects&quot;/&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">float</span> DisplayRotation <span style="color: #008000;">&#123;</span> get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> displayRotation<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets the SpriteEffects for the display's render target.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;seealso cref=&quot;DisplayRotation&quot;/&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> SpriteEffects DisplaySpriteEffects <span style="color: #008000;">&#123;</span> get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> displaySpriteEffects<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets whether or not the application has been loaded.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsLoaded <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets or Sets the clear color of the graphics device.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">protected</span> Color ClearColor <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets the SpriteBatch used to draw the main render target.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">protected</span> SpriteBatch SpriteBatch <span style="color: #008000;">&#123;</span> get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> spriteBatch<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets or Sets the target frame rate for the underlying loop code.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">float</span> TargetFrameRate
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #FF0000;">1</span> <span style="color: #008000;">/</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span>TargetElapsedTime<span style="color: #008000;">.</span><span style="color: #0000FF;">TotalSeconds</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
            set
            <span style="color: #008000;">&#123;</span>
                TargetElapsedTime <span style="color: #008000;">=</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">FromSeconds</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1</span> <span style="color: #008000;">/</span> value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">public</span> ModuleCollection Modules <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2009/11/16/fgf-its-all-about-abstraction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FGF: Getting Started</title>
		<link>http://jsedlak.org/2009/11/05/fgf-getting-started/</link>
		<comments>http://jsedlak.org/2009/11/05/fgf-getting-started/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 15:08:52 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[FGF]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://jsedlak.com/?p=246</guid>
		<description><![CDATA[This series is devoted to the design and development of my framework, FGF (Focused Games Framework), and aims to cover topics like async content management, WCF services, and many more. In this first article, I cover how to setup Visual Studio 2008 for coding the framework. It is important to understand that I will be [...]]]></description>
			<content:encoded><![CDATA[<p>This series is devoted to the design and development of my framework, FGF (Focused Games Framework), and aims to cover topics like async content management, WCF services, and many more. In this first article, I cover how to setup Visual Studio 2008 for coding the framework. It is important to understand that I will be using Visual Studio Team System 2008 and thus may have features that are not available in the Express edition. It is possible to get around many of these or ignore them completely, however, so not having Team System does not mean developing FGF is impossible.</p>
<p>The first step is to open up the IDE and create our solution. When starting a large solution such as the one for FGF, I find it useful to create a <i>Blank Solution</i> so that the solution&#8217;s name can be different than that of the first project. Again, this can be worked around in Express as well as other versions of the editor.</p>
<div class="Center"><img class="Bordered" src="/wp-content/uploads/2009/11/screenshot_9-300x222.jpg" alt="Blank FGF Solution" title="Blank FGF Solution" width="300" height="222" class="size-medium wp-image-247" /></div>
<p><span id="more-246"></span></p>
<p>The next step is an obvious one: add the first project. The design of FGF is based on a hierarchy of libraries much like the .NET Framework. Whereas libraries depend on the System DLL and mscorlib, FGF libraries can all depend on the core project, FocusedGames. To enable some cross-platform awesomeness down the road, we make this project an XNA library and then remove the references to the XNA Framework. Remember that FGF is not just an XNA framework and should support situations where XNA is not installed. You can see the cleaned project in the below screenshot.</p>
<div class="Center"><img class="Bordered" src="/wp-content/uploads/2009/11/screenshot_11-279x300.jpg" alt="First project in FGF" title="First project in FGF" width="279" height="300" class="size-medium wp-image-248" /></div>
<p>After creating some copy projects for the Zune and the Xbox 360, repeat the process for a new project, FocusedGames.Xna. At this point you may find it nice to move the platform specific projects into platform specific Solution Folders. This is one of the features of Visual Studio I wish was present in the Express Edition, but unfortunately it was left out. The really nice part of Solution Folders is that it does not physically move the project files. Rather it simply organizes them in a virtual fashion.</p>
<p>Regardless, the last step is to setup the output directory. Personally, I like having the projects all push to the same bin folder so I can copy them with a Powershell script very easily. To do this, go into each project&#8217;s properties and change the output directory to something like &#8220;..\Bin\whatever was here>&#8221; and remember to change it for both Debug and Release.</p>
<div class="Center"><a href="/wp-content/uploads/2009/11/screenshot_12.jpg"><img src="http://jsedlak.com/wp-content/uploads/2009/11/screenshot_12-300x222.jpg" alt="Changing the output directory..." title="Changing the output directory..." width="300" height="222" class="Bordered" /></a></div>
<p>Finally we are ready to start coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2009/11/05/fgf-getting-started/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2D Fog Of War</title>
		<link>http://jsedlak.org/2009/10/27/2d-fog-of-war/</link>
		<comments>http://jsedlak.org/2009/10/27/2d-fog-of-war/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 13:44:35 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[2D]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Fog Of War]]></category>

		<guid isPermaLink="false">http://jsedlak.com/?p=231</guid>
		<description><![CDATA[This tutorial covers a basic way of implementing two dimensional fog of war for a game in XNA and assumes you (the reader) has basic knowledge of C# and the XNA Framework. To get things started, create an empty Windows game project. Two textures will be needed: one for the Light and one for the [...]]]></description>
			<content:encoded><![CDATA[<div class="Center"><a href="/wp-content/uploads/2009/10/screenshot_7.jpg"><img class="Bordered" src="/wp-content/uploads/2009/10/screenshot_7-300x233.jpg" alt="Fog Of War Sample" title="Fog Of War Sample" width="300" height="233" class="size-medium wp-image-233" /></a></div>
<p>This tutorial covers a basic way of implementing two dimensional fog of war for a game in XNA and assumes you (the reader) has basic knowledge of C# and the XNA Framework. To get things started, create an empty Windows game project. Two textures will be needed: one for the <a href="http://jsedlak.com/images/articles/fogofwar/Light.png">Light</a> and one for the <a href="http://jsedlak.com/images/articles/fogofwar/Background.jpg">Background</a>. After adding these to the Content Project, go ahead and add the following members to the game class.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p231code65'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23165"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p231code65"><pre class="csharp" style="font-family:monospace;">Texture2D lightTexture<span style="color: #008000;">;</span>
Texture2D backgroundTexture<span style="color: #008000;">;</span>
&nbsp;
RenderTarget2D lightTarget<span style="color: #008000;">;</span>
RenderTarget2D mainTarget<span style="color: #008000;">;</span>
&nbsp;
Effect basicFogOfWarEffect<span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>While the use of the texture fields is obvious, the use of the render targets may not. The concept behind this fog of war implementation is to draw the light texture to the <i>lightTarget</i> render target and then use the produced texture as the alpha channel for the texture produced from the <i>mainTarget</i> render target.</p>
<p><span id="more-231"></span></p>
<p>The next task is to load up the textures and create the render targets. <b>Note:</b> If you have issues with the render targets, you may have to change the create statement for your GPU. A better render target creation method will be added to this article at a later date.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p231code66'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23166"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p231code66"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> LoadContent<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Create a new SpriteBatch, which can be used to draw textures.</span>
    spriteBatch <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SpriteBatch<span style="color: #008000;">&#40;</span>GraphicsDevice<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    lightTexture <span style="color: #008000;">=</span> Content<span style="color: #008000;">.</span><span style="color: #0000FF;">Load</span><span style="color: #008000;">&lt;</span>Texture2D<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Light&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    backgroundTexture <span style="color: #008000;">=</span> Content<span style="color: #008000;">.</span><span style="color: #0000FF;">Load</span><span style="color: #008000;">&lt;</span>Texture2D<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Background&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    basicFogOfWarEffect <span style="color: #008000;">=</span> Content<span style="color: #008000;">.</span><span style="color: #0000FF;">Load</span><span style="color: #008000;">&lt;</span>Effect<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Effects/BasicFogOfWar&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    mainTarget <span style="color: #008000;">=</span> CreateRenderTarget<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    lightTarget <span style="color: #008000;">=</span> CreateRenderTarget<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">LoadContent</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">private</span> RenderTarget2D CreateRenderTarget<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">new</span> RenderTarget2D<span style="color: #008000;">&#40;</span>GraphicsDevice, GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">PresentationParameters</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BackBufferWidth</span>, GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">PresentationParameters</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BackBufferHeight</span>, <span style="color: #FF0000;">1</span>, SurfaceFormat<span style="color: #008000;">.</span><span style="color: #0000FF;">Color</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Finally the drawing can begin. The process is incredibly simple and straight forward: draw the game, draw the lights, combine the two and draw to the screen. First the &quot;game&quot; is drawn to the <i>mainTarget</i> render target.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p231code67'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23167"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p231code67"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> DrawMain<span style="color: #008000;">&#40;</span>GameTime gameTime<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">SetRenderTarget</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, mainTarget<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">Clear</span><span style="color: #008000;">&#40;</span>Color<span style="color: #008000;">.</span><span style="color: #0000FF;">Black</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// Draw the background</span>
    spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Begin</span><span style="color: #008000;">&#40;</span>SpriteBlendMode<span style="color: #008000;">.</span><span style="color: #0000FF;">AlphaBlend</span>, SpriteSortMode<span style="color: #008000;">.</span><span style="color: #0000FF;">Immediate</span>, SaveStateMode<span style="color: #008000;">.</span><span style="color: #0000FF;">SaveState</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span>
        backgroundTexture,
        <span style="color: #008000;">new</span> Rectangle<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">PresentationParameters</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BackBufferWidth</span>, GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">PresentationParameters</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BackBufferHeight</span><span style="color: #008000;">&#41;</span>,
        Color<span style="color: #008000;">.</span><span style="color: #0000FF;">White</span>
    <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">End</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">SetRenderTarget</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Step two is to draw the lights. For now drawing based on where the mouse will do nicely for a test.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p231code68'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23168"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code" id="p231code68"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">void</span> DrawLights<span style="color: #008000;">&#40;</span>GameTime gameTime<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">SetRenderTarget</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, lightTarget<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">Clear</span><span style="color: #008000;">&#40;</span>Color<span style="color: #008000;">.</span><span style="color: #0000FF;">Black</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    MouseState mouseState <span style="color: #008000;">=</span> Mouse<span style="color: #008000;">.</span><span style="color: #0000FF;">GetState</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Begin</span><span style="color: #008000;">&#40;</span>SpriteBlendMode<span style="color: #008000;">.</span><span style="color: #0000FF;">AlphaBlend</span>, SpriteSortMode<span style="color: #008000;">.</span><span style="color: #0000FF;">Immediate</span>, SaveStateMode<span style="color: #008000;">.</span><span style="color: #0000FF;">SaveState</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span>
        lightTexture,
        <span style="color: #008000;">new</span> Vector2<span style="color: #008000;">&#40;</span>mouseState<span style="color: #008000;">.</span><span style="color: #0000FF;">X</span>, mouseState<span style="color: #008000;">.</span><span style="color: #0000FF;">Y</span><span style="color: #008000;">&#41;</span>,
        <span style="color: #0600FF; font-weight: bold;">null</span>,
        Color<span style="color: #008000;">.</span><span style="color: #0000FF;">White</span>,
        0f,
        <span style="color: #008000;">new</span> Vector2<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">16</span>, <span style="color: #FF0000;">16</span><span style="color: #008000;">&#41;</span>,
        Vector2<span style="color: #008000;">.</span><span style="color: #0000FF;">One</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">16</span>,
        SpriteEffects<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span>,
        1<span style="color: #008000;">.</span>0f
    <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">End</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">SetRenderTarget</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>And finally these methods are put together and the final is drawn with the effect.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p231code69'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23169"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code" id="p231code69"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">void</span> Draw<span style="color: #008000;">&#40;</span>GameTime gameTime<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    DrawMain<span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    DrawLights<span style="color: #008000;">&#40;</span>gameTime<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">Clear</span><span style="color: #008000;">&#40;</span>Color<span style="color: #008000;">.</span><span style="color: #0000FF;">Black</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    Texture2D mainTex <span style="color: #008000;">=</span> mainTarget<span style="color: #008000;">.</span><span style="color: #0000FF;">GetTexture</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    Texture2D lightTex <span style="color: #008000;">=</span> lightTarget<span style="color: #008000;">.</span><span style="color: #0000FF;">GetTexture</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    basicFogOfWarEffect<span style="color: #008000;">.</span><span style="color: #0000FF;">Parameters</span><span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;LightsTexture&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">SetValue</span><span style="color: #008000;">&#40;</span>lightTex<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Begin</span><span style="color: #008000;">&#40;</span>SpriteBlendMode<span style="color: #008000;">.</span><span style="color: #0000FF;">AlphaBlend</span>, SpriteSortMode<span style="color: #008000;">.</span><span style="color: #0000FF;">Immediate</span>, SaveStateMode<span style="color: #008000;">.</span><span style="color: #0000FF;">SaveState</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    basicFogOfWarEffect<span style="color: #008000;">.</span><span style="color: #0000FF;">Begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    basicFogOfWarEffect<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentTechnique</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Passes</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span>
        mainTex,
        <span style="color: #008000;">new</span> Rectangle<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">0</span>, GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">PresentationParameters</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BackBufferWidth</span>, GraphicsDevice<span style="color: #008000;">.</span><span style="color: #0000FF;">PresentationParameters</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BackBufferHeight</span><span style="color: #008000;">&#41;</span>,
        Color<span style="color: #008000;">.</span><span style="color: #0000FF;">White</span>
    <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">End</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    basicFogOfWarEffect<span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentTechnique</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Passes</span><span style="color: #008000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">End</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    basicFogOfWarEffect<span style="color: #008000;">.</span><span style="color: #0000FF;">End</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The effect itself is incredibly simple. Combine the two textures but use a channel from the &#8220;light&#8221; texture as the alpha for the color (screen facing) texture.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p231code70'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23170"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code" id="p231code70"><pre class="csharp" style="font-family:monospace;">texture LightsTexture<span style="color: #008000;">;</span>
&nbsp;
sampler  ColorSampler  <span style="color: #008000;">:</span> register<span style="color: #008000;">&#40;</span>s0<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
sampler LightsSampler <span style="color: #008000;">=</span> sampler_state<span style="color: #008000;">&#123;</span>
	Texture <span style="color: #008000;">=</span> <span style="color: #008000;">&lt;</span>LightsTexture<span style="color: #008000;">&gt;;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #6666cc; font-weight: bold;">struct</span> VertexShaderOutput
<span style="color: #008000;">&#123;</span>
    float4 Position <span style="color: #008000;">:</span> POSITION0<span style="color: #008000;">;</span>
    float2 TexCoord <span style="color: #008000;">:</span> TEXCOORD0<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
float4 PixelShaderFunction<span style="color: #008000;">&#40;</span>VertexShaderOutput input<span style="color: #008000;">&#41;</span> <span style="color: #008000;">:</span> COLOR0
<span style="color: #008000;">&#123;</span>
	float2 tex <span style="color: #008000;">=</span> input<span style="color: #008000;">.</span><span style="color: #0000FF;">TexCoord</span><span style="color: #008000;">;</span>
&nbsp;
    float4 color <span style="color: #008000;">=</span> tex2D<span style="color: #008000;">&#40;</span>ColorSampler, tex<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    float4 alpha <span style="color: #008000;">=</span> tex2D<span style="color: #008000;">&#40;</span>LightsSampler, tex<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">return</span> float4<span style="color: #008000;">&#40;</span>color<span style="color: #008000;">.</span><span style="color: #0000FF;">r</span>, color<span style="color: #008000;">.</span><span style="color: #0000FF;">g</span>, color<span style="color: #008000;">.</span><span style="color: #0000FF;">b</span>, alpha<span style="color: #008000;">.</span><span style="color: #0000FF;">r</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
technique Technique1
<span style="color: #008000;">&#123;</span>
    pass Pass1
    <span style="color: #008000;">&#123;</span>
        PixelShader <span style="color: #008000;">=</span> compile ps_2_0 PixelShaderFunction<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Download: <a class="downloadlink" href="http://jsedlak.org/wp-content/plugins/download-monitor/download.php?id=2" title="Version1.0 downloaded 285 times" >Fog Of War Sample (285)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2009/10/27/2d-fog-of-war/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Zune HD: Calling GetState Twice</title>
		<link>http://jsedlak.org/2009/10/05/zune-hd-calling-getstate-twice/</link>
		<comments>http://jsedlak.org/2009/10/05/zune-hd-calling-getstate-twice/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 19:32:13 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[Zune]]></category>
		<category><![CDATA[Zune HD]]></category>

		<guid isPermaLink="false">http://jsedlak.com/?p=226</guid>
		<description><![CDATA[Beware that when you call TouchPanel.GetState twice within the game loop, what touch locations had a Pressed state the first time will have a Moved state the second time. Consider the following lines of code. ?View Code CSHARP1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [...]]]></description>
			<content:encoded><![CDATA[<p>Beware that when you call TouchPanel.GetState twice within the game loop, what touch locations had a Pressed state the first time will have a Moved state the second time. Consider the following lines of code.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p226code72'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p22672"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code" id="p226code72"><pre class="csharp" style="font-family:monospace;">TouchCollection touches <span style="color: #008000;">=</span> TouchPanel<span style="color: #008000;">.</span><span style="color: #0000FF;">GetState</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>TouchLocation locale <span style="color: #0600FF; font-weight: bold;">in</span> touches<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>locale<span style="color: #008000;">.</span><span style="color: #0000FF;">State</span> <span style="color: #008000;">==</span> TouchLocationState<span style="color: #008000;">.</span><span style="color: #0000FF;">Released</span> <span style="color: #008000;">&amp;&amp;</span> locale<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span> <span style="color: #008000;">==</span> id1<span style="color: #008000;">&#41;</span>
        id1 <span style="color: #008000;">=</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>locale<span style="color: #008000;">.</span><span style="color: #0000FF;">State</span> <span style="color: #008000;">==</span> TouchLocationState<span style="color: #008000;">.</span><span style="color: #0000FF;">Pressed</span> <span style="color: #008000;">&amp;&amp;</span> id1 <span style="color: #008000;">==</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span>
        id1 <span style="color: #008000;">=</span> locale<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">else</span> <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>locale<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span> <span style="color: #008000;">==</span> id1<span style="color: #008000;">&#41;</span>
        pos1 <span style="color: #008000;">=</span> locale<span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
touches <span style="color: #008000;">=</span> TouchPanel<span style="color: #008000;">.</span><span style="color: #0000FF;">GetState</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>TouchLocation locale <span style="color: #0600FF; font-weight: bold;">in</span> touches<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Can fail if the first time through it was Pressed.</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>locale<span style="color: #008000;">.</span><span style="color: #0000FF;">Id</span> <span style="color: #008000;">==</span> id1 <span style="color: #008000;">&amp;&amp;</span> locale<span style="color: #008000;">.</span><span style="color: #0000FF;">State</span> <span style="color: #008000;">==</span> TouchLocationState<span style="color: #008000;">.</span><span style="color: #0000FF;">Pressed</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Do something important</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Note that it isn&#8217;t important that these are in the same file let alone the same method. You cannot rely on having access to the same state data everytime you call GetState within the game&#8217;s loop. So it will probably become important to put the touch code in a global location and store the states for the duration of the loop. For instance you can store the TouchCollection data in a static variable at the top of the Game&#8217;s Update method.</p>
]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2009/10/05/zune-hd-calling-getstate-twice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To: Zune HD Touch Testing</title>
		<link>http://jsedlak.org/2009/10/02/how-to-zune-hd-touch-testing/</link>
		<comments>http://jsedlak.org/2009/10/02/how-to-zune-hd-touch-testing/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 19:59:39 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[Zune HD]]></category>

		<guid isPermaLink="false">http://jsedlak.com/?p=208</guid>
		<description><![CDATA[One of the first &#8220;games&#8221; I made for the Zune HD was a simple little application to test how accurate and quick the touch panel is. This How To gives you the code to get started with your own basic testing application. After creating a Zune game with XNA 3.1, the first thing you need [...]]]></description>
			<content:encoded><![CDATA[<div class="Center"><span class="ImgLink"><img src="/images/Zune/Kaitlin-11.png" alt="Touch Testing on Zune HD"/></span></div>
<p>One of the first &#8220;games&#8221; I made for the Zune HD was a simple little application to test how accurate and quick the touch panel is. This <i>How To</i> gives you the code to get started with your own basic testing application.</p>
<p>After creating a Zune game with XNA 3.1, the first thing you need to do is define a basic particle struct to hold some data that we track as the user touches the screen. Specifically we need to track whether or not a particle is active (do we update it and draw it?), its position and its life (how long it has been there). I created this structure within the Game1 class but really it can go anywhere.</p>
<p><span id="more-208"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p208code80'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20880"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p208code80"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">struct</span> TouchSpot
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> Vector2 Position<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">float</span> Life, MaxLife<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsActive<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>After creating the structure, two new private members need to be added to the game so we can actually, you know, do stuff.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p208code81'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20881"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p208code81"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> Texture2D texture<span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">private</span> TouchSpot<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> spots <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TouchSpot<span style="color: #008000;">&#91;</span><span style="color: #FF0000;">2048</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p><b>Note:</b> I found it useful to update the <i>TargetElapsedTime</i> property to reflect 60 frames per second rather than 30 frames per second. This allows the update routine to be run more often and therefore more particles to be created!</p>
<p>Next on the list is to load the texture. You can use any texture you want; I chose to use a simple circle that fades out.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p208code82'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20882"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p208code82"><pre class="csharp" style="font-family:monospace;">texture <span style="color: #008000;">=</span> Content<span style="color: #008000;">.</span><span style="color: #0000FF;">Load</span><span style="color: #008000;">&lt;</span>Texture2D<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Touch&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>Finally we get to the real meat of the game: the Update function. First we update each &#8220;particle&#8221; by decreasing its life and checking whether or not its &#8220;clock&#8221; has run out. This allows us to fade the particles out over time and creates a nice effect.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p208code83'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20883"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p208code83"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">float</span> et <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">float</span><span style="color: #008000;">&#41;</span>gameTime<span style="color: #008000;">.</span><span style="color: #0000FF;">ElapsedGameTime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">TotalSeconds</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> spots<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>spots<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsActive</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">continue</span><span style="color: #008000;">;</span>
&nbsp;
    spots<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Life</span> <span style="color: #008000;">-=</span> <span style="color: #008000;">&#40;</span>et <span style="color: #008000;">*</span> <span style="color: #FF0000;">10</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>spots<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Life</span> <span style="color: #008000;">&lt;=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span>
        spots<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsActive</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Next we gather the touch points from the panel and reset particles in our array if possible. Note that we scale the pressure so that the particles don&#8217;t instantly disappear.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p208code84'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20884"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p208code84"><pre class="csharp" style="font-family:monospace;">TouchCollection touchPoints <span style="color: #008000;">=</span> TouchPanel<span style="color: #008000;">.</span><span style="color: #0000FF;">GetState</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>TouchLocation location <span style="color: #0600FF; font-weight: bold;">in</span> touchPoints<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">int</span> index <span style="color: #008000;">=</span> FindInactiveSpot<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>index <span style="color: #008000;">==</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">break</span><span style="color: #008000;">;</span>
&nbsp;
    spots<span style="color: #008000;">&#91;</span>index<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span> <span style="color: #008000;">=</span> location<span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span><span style="color: #008000;">;</span>
    spots<span style="color: #008000;">&#91;</span>index<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Life</span> <span style="color: #008000;">=</span> location<span style="color: #008000;">.</span><span style="color: #0000FF;">Pressure</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1000</span><span style="color: #008000;">;</span>
    spots<span style="color: #008000;">&#91;</span>index<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MaxLife</span> <span style="color: #008000;">=</span> location<span style="color: #008000;">.</span><span style="color: #0000FF;">Pressure</span> <span style="color: #008000;">*</span> <span style="color: #FF0000;">1000</span><span style="color: #008000;">;</span>
    spots<span style="color: #008000;">&#91;</span>index<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsActive</span> <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The Update method places a call to the <i>FindInactiveSpot</i> function which searches the array for particles that are no longer active and returns the index.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p208code85'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20885"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p208code85"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">int</span> FindInactiveSpot<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> spots<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>spots<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsActive</span><span style="color: #008000;">&#41;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> i<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>Last but certainly important is the draw method which draws all currently active particles. We divide the <i>Life</i> by the <i>MaxLife</i> to get a percentage of how &#8220;healthy&#8221; a particle is. This is an implementation of a fade out for each particle.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p208code86'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20886"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p208code86"><pre class="csharp" style="font-family:monospace;">spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Begin</span><span style="color: #008000;">&#40;</span>SpriteBlendMode<span style="color: #008000;">.</span><span style="color: #0000FF;">AlphaBlend</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> spots<span style="color: #008000;">.</span><span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>spots<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsActive</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">continue</span><span style="color: #008000;">;</span>
&nbsp;
    spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">Draw</span><span style="color: #008000;">&#40;</span>
        texture,
        spots<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Position</span>,
        <span style="color: #0600FF; font-weight: bold;">null</span>,
        <span style="color: #008000;">new</span> Color<span style="color: #008000;">&#40;</span>1f, 1f, 1f, spots<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Life</span> <span style="color: #008000;">/</span> spots<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MaxLife</span><span style="color: #008000;">&#41;</span>,
        0f,
        <span style="color: #008000;">new</span> Vector2<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">16</span>, <span style="color: #FF0000;">16</span><span style="color: #008000;">&#41;</span>,
        spots<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Life</span> <span style="color: #008000;">/</span> spots<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MaxLife</span> <span style="color: #008000;">*</span> 1<span style="color: #008000;">.</span>5f,
        SpriteEffects<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span>,
        1f
    <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
spriteBatch<span style="color: #008000;">.</span><span style="color: #0000FF;">End</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>And there you have it, a method for testing the capabilities of your Zune HD&#8217;s touch panel!</p>
<p>Sample Code: <a class="downloadlink" href="http://jsedlak.org/wp-content/plugins/download-monitor/download.php?id=1" title="Version1.0 downloaded 258 times" >Zune HD Touch Panel Testing (258)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2009/10/02/how-to-zune-hd-touch-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cross Platform XNA Projects (X64 Content)</title>
		<link>http://jsedlak.org/2009/09/05/cross-platform-xna-projects-x64-content/</link>
		<comments>http://jsedlak.org/2009/09/05/cross-platform-xna-projects-x64-content/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 17:42:24 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://jsedlak.com/?p=197</guid>
		<description><![CDATA[One of the requirements of the framework I am building (FGF) is cross platform support. For my XNA games this means support for not only Windows but also the Zune and the Xbox 360. For my Windows based projects I often find that X64 can be used (and in the case of IIS in 2008 [...]]]></description>
			<content:encoded><![CDATA[<p>One of the requirements of the framework I am building (<a href="http://focusedgames.com/fg-framework">FGF</a>) is cross platform support. For my XNA games this means support for not only Windows but also the Zune and the Xbox 360. For my Windows based projects I often find that X64 can be used (and in the case of IIS in 2008 R2, encouraged) so I also support X64 versions.</p>
<p>The problem is that when using an XNA project template to build a library for the simple fact that XNA projects can automatically synchronized (across platforms), Visual Studio blocks the creation of an X64 build target. Rather you are stuck with X86, Zune or Xbox 360.</p>
<p>The good news is that you can get around this! Open up the Windows project file (csproj) in a suitable text editor and copy the sections for both &#8220;Debug|x86&#8243; and &#8220;Release|x86&#8243; and paste them right after.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p197code89'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p19789"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code" id="p197code89"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>PropertyGroup Condition<span style="color: #008000;">=</span><span style="color: #666666;">&quot; '$(Configuration)|$(Platform)' == 'Debug|x86' &quot;</span><span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>DebugSymbols<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&lt;/</span>DebugSymbols<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>DebugType<span style="color: #008000;">&gt;</span>full<span style="color: #008000;">&lt;/</span>DebugType<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>Optimize<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&lt;/</span>Optimize<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>OutputPath<span style="color: #008000;">&gt;..</span>\Bin\x86\Debug\<span style="color: #008000;">&lt;/</span>OutputPath<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>DefineConstants<span style="color: #008000;">&gt;</span>DEBUG<span style="color: #008000;">;</span>TRACE<span style="color: #008000;">;</span>WINDOWS<span style="color: #008000;">&lt;/</span>DefineConstants<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>ErrorReport<span style="color: #008000;">&gt;</span>prompt<span style="color: #008000;">&lt;/</span>ErrorReport<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>WarningLevel<span style="color: #008000;">&gt;</span><span style="color: #FF0000;">4</span><span style="color: #008000;">&lt;/</span>WarningLevel<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>NoStdLib<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&lt;/</span>NoStdLib<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>UseVSHostingProcess<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&lt;/</span>UseVSHostingProcess<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>PlatformTarget<span style="color: #008000;">&gt;</span>x86<span style="color: #008000;">&lt;/</span>PlatformTarget<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>XnaCompressContent<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&lt;/</span>XnaCompressContent<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>PropertyGroup<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>PropertyGroup Condition<span style="color: #008000;">=</span><span style="color: #666666;">&quot; '$(Configuration)|$(Platform)' == 'Release|x86' &quot;</span><span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>DebugType<span style="color: #008000;">&gt;</span>pdbonly<span style="color: #008000;">&lt;/</span>DebugType<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>Optimize<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&lt;/</span>Optimize<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>OutputPath<span style="color: #008000;">&gt;..</span>\Bin\x86\Release\<span style="color: #008000;">&lt;/</span>OutputPath<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>DefineConstants<span style="color: #008000;">&gt;</span>TRACE<span style="color: #008000;">;</span>WINDOWS<span style="color: #008000;">&lt;/</span>DefineConstants<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>ErrorReport<span style="color: #008000;">&gt;</span>prompt<span style="color: #008000;">&lt;/</span>ErrorReport<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>WarningLevel<span style="color: #008000;">&gt;</span><span style="color: #FF0000;">4</span><span style="color: #008000;">&lt;/</span>WarningLevel<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>NoStdLib<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&lt;/</span>NoStdLib<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>UseVSHostingProcess<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&lt;/</span>UseVSHostingProcess<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>PlatformTarget<span style="color: #008000;">&gt;</span>x86<span style="color: #008000;">&lt;/</span>PlatformTarget<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>XnaCompressContent<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&lt;/</span>XnaCompressContent<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>PropertyGroup<span style="color: #008000;">&gt;</span></pre></td></tr></table></div>

<p>Next you simply replace the instances of x86 with x64 and change anything else you need.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p197code90'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p19790"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code" id="p197code90"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>PropertyGroup Condition<span style="color: #008000;">=</span><span style="color: #666666;">&quot; '$(Configuration)|$(Platform)' == 'Debug|x64' &quot;</span><span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>DebugSymbols<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&lt;/</span>DebugSymbols<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>DebugType<span style="color: #008000;">&gt;</span>full<span style="color: #008000;">&lt;/</span>DebugType<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>Optimize<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&lt;/</span>Optimize<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>OutputPath<span style="color: #008000;">&gt;..</span>\Bin\x64\Debug\<span style="color: #008000;">&lt;/</span>OutputPath<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>DefineConstants<span style="color: #008000;">&gt;</span>DEBUG<span style="color: #008000;">;</span>TRACE<span style="color: #008000;">;</span>WINDOWS<span style="color: #008000;">&lt;/</span>DefineConstants<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>ErrorReport<span style="color: #008000;">&gt;</span>prompt<span style="color: #008000;">&lt;/</span>ErrorReport<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>WarningLevel<span style="color: #008000;">&gt;</span><span style="color: #FF0000;">4</span><span style="color: #008000;">&lt;/</span>WarningLevel<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>NoStdLib<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&lt;/</span>NoStdLib<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>UseVSHostingProcess<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&lt;/</span>UseVSHostingProcess<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>PlatformTarget<span style="color: #008000;">&gt;</span>x64<span style="color: #008000;">&lt;/</span>PlatformTarget<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>XnaCompressContent<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&lt;/</span>XnaCompressContent<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>PropertyGroup<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>PropertyGroup Condition<span style="color: #008000;">=</span><span style="color: #666666;">&quot; '$(Configuration)|$(Platform)' == 'Release|x64' &quot;</span><span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>DebugType<span style="color: #008000;">&gt;</span>pdbonly<span style="color: #008000;">&lt;/</span>DebugType<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>Optimize<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&lt;/</span>Optimize<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>OutputPath<span style="color: #008000;">&gt;..</span>\Bin\x64\Release\<span style="color: #008000;">&lt;/</span>OutputPath<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>DefineConstants<span style="color: #008000;">&gt;</span>TRACE<span style="color: #008000;">;</span>WINDOWS<span style="color: #008000;">&lt;/</span>DefineConstants<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>ErrorReport<span style="color: #008000;">&gt;</span>prompt<span style="color: #008000;">&lt;/</span>ErrorReport<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>WarningLevel<span style="color: #008000;">&gt;</span><span style="color: #FF0000;">4</span><span style="color: #008000;">&lt;/</span>WarningLevel<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>NoStdLib<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&lt;/</span>NoStdLib<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>UseVSHostingProcess<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">&lt;/</span>UseVSHostingProcess<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>PlatformTarget<span style="color: #008000;">&gt;</span>x64<span style="color: #008000;">&lt;/</span>PlatformTarget<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>XnaCompressContent<span style="color: #008000;">&gt;</span><span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&lt;/</span>XnaCompressContent<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>PropertyGroup<span style="color: #008000;">&gt;</span></pre></td></tr></table></div>

<p>One warning &#8211; this should only be used for projects that don&#8217;t require references to the XNA framework. At this time Microsoft has no support for x64 XNA references.</p>
]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2009/09/05/cross-platform-xna-projects-x64-content/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
