<?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/tag/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 Gets A License</title>
		<link>http://jsedlak.org/2010/08/04/fgf-gets-a-license/</link>
		<comments>http://jsedlak.org/2010/08/04/fgf-gets-a-license/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 10:34:35 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[FGF]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://jsedlak.org/?p=680</guid>
		<description><![CDATA[A quick update of FGF with a bump to version 0.1.3.0 on the core libraries and the inclusion of a license. I have decided to go with the MIT License because I want to enable developers to use FGF for their commercial projects and enable redistribution. The only thing I ask is that if you [...]]]></description>
			<content:encoded><![CDATA[<p>A quick update of FGF with a bump to version 0.1.3.0 on the core libraries and the inclusion of a license. I have decided to go with the <a href="http://en.wikipedia.org/wiki/MIT_License">MIT License</a> because I want to enable developers to use FGF for their commercial projects and enable redistribution. The only thing I ask is that if you do make an improvement or a fix, consider sending the changes to me so that I may improve the original codebase.</p>
<p>The new release includes the first version of the new XML serialization classes and numerous fixes. The <a href="/clickonce/fgf/License.txt">License</a> is included with the following downloads.</p>
<a href="http://jsedlak.org/wp-content/plugins/download-monitor/download.php?id=27" title="Downloaded 108 times.">FGF Binaries v0.1.3.0 (108)</a><br/><br />
<a href="http://jsedlak.org/wp-content/plugins/download-monitor/download.php?id=28" title="Downloaded 22 times.">FGF Source v0.1.3.0 (22)</a>
]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2010/08/04/fgf-gets-a-license/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>That&#8217;s Twitterific!</title>
		<link>http://jsedlak.org/2010/02/11/thats-twitterific/</link>
		<comments>http://jsedlak.org/2010/02/11/thats-twitterific/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 13:29:00 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://jsedlak.org/?p=581</guid>
		<description><![CDATA[Are you new to Twitter? Are you looking for some interesting people to follow? What follows is an introduction to who you should be following on Twitter. It is by no means a complete compilation of who I think is important but rather the beginning. XNA MVP List This is a compiled list of the [...]]]></description>
			<content:encoded><![CDATA[<p>Are you new to <a href="http://twitter.com">Twitter</a>? Are you looking for some interesting people to follow? What follows is an introduction to who you should be following on Twitter. It is by no means a complete compilation of who I think is important but rather the beginning.</p>
<ul>
<li><a href="http://twitter.com/mklucher/xna-mvp">XNA MVP List</a>
<p>This is a compiled list of the XNA MVPs known to be twittering. If you are interested in XNA, you should be following these guys!</p>
</li>
<li><a href="http://twitter.com/mklucher">Michael Klucher</a>
<p>Speaking of Klucher, he is the Lead Program Manager of the XNA Development Platform at Microsoft. Follow him for an interesting view of the daily life of a Microsoftie.
</li>
<li><a href="http://twitter.com/thurrott">Paul Thurrott</a>
<p>Best known for his <a href="http://winsupersite.com">website</a>, Paul offers a fantastic viewpoint on the industry and is constantly on top of the latest products coming out of Redmond.</p>
</li>
<li><a href="http://twitter.com/billgates">Bill Gates</a>
<p>Gates is finally twittering! Follow him to stay up to date on his work and travels related to the <a href="http://www.gatesfoundation.org">Bill &amp; Melinda Gates Foundation</a>.</p>
</li>
<li><a href="http://twitter.com/shawnhargreaves">Shawn Hargreaves</a>
<p>Shawn, famous for his cat based tutorials has one of the best XNA blogs out there. If you are an XNA developer and don&#8217;t know him, you&#8217;re living under a rock.</p>
</li>
<li><a href="http://twitter.com/sgtconker">Sgt. Conker</a>
<p>Keeping up to date on all things XNA can be a daunting task some times. Thankfully <a href="http://sgtconker.com">Sgt. Conker</a> has got you covered! Follow these guys for the latest news, articles, videos and releases.</p>
</li>
<li><a href="http://twitter.com/skastudios">Ska Studios</a>
<p>Dishwasher. Charlie Murder. GAME WITH ZOMBIES. What else needs to be said? The leader in XNA game development. Follow for news not just about their latest creation but gatos as well.</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2010/02/11/thats-twitterific/feed/</wfw:commentRss>
		<slash:comments>1</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: A Base Class For INotifyPropertyChanged</title>
		<link>http://jsedlak.org/2010/01/31/fgf-a-base-class-for-inotifypropertychanged/</link>
		<comments>http://jsedlak.org/2010/01/31/fgf-a-base-class-for-inotifypropertychanged/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 13:06:17 +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=569</guid>
		<description><![CDATA[One piece of functionality I consistently find myself writing and rewriting is the implementation of the INotifyPropertyChanged interface. This class, located in the main FGF library, makes that rewriting unnecessary by implementing it in an open way. ?View Code CSHARP1 2 3 4 5 public class NotifyPropertyChangedBase : INotifyPropertyChanged &#123; private bool isDirty = false; [...]]]></description>
			<content:encoded><![CDATA[<p>One piece of functionality I consistently find myself writing and rewriting is the implementation of the INotifyPropertyChanged interface. This class, located in the main FGF library, makes that rewriting unnecessary by implementing it in an open way.</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('p569code31'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p56931"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p569code31"><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> NotifyPropertyChangedBase <span style="color: #008000;">:</span> INotifyPropertyChanged
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">private</span> <span style="color: #6666cc; font-weight: bold;">bool</span> isDirty <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</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> PropertyChangedEventHandler PropertyChanged<span style="color: #008000;">;</span></pre></td></tr></table></div>

<p><span id="more-569"></span></p>
<p>A virtual method is then added to allow end developers to change how the class reacts to when properties are 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('p569code32'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p56932"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p569code32"><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;">bool</span> CanSetDirty<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;">!</span>DisableDirtyFlag<span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>To fire the event, a simple method is written that can be used by end developers. This method makes a call to a virtual method that actually fires the event and sets the IsDirty 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('p569code33'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p56933"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p569code33"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> OnPropertyChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> propertyName<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        OnPropertyChanged<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">this</span>, <span style="color: #008000;">new</span> PropertyChangedEventArgs<span style="color: #008000;">&#40;</span>propertyName<span style="color: #008000;">&#41;</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> OnPropertyChanged<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, PropertyChangedEventArgs 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>args<span style="color: #008000;">.</span><span style="color: #0000FF;">PropertyName</span> <span style="color: #008000;">!=</span> <span style="color: #666666;">&quot;IsDirty&quot;</span><span style="color: #008000;">&#41;</span>
            IsDirty <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;">if</span> <span style="color: #008000;">&#40;</span>PropertyChanged <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span> PropertyChanged<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>And finally 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('p569code34'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p56934"><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="p569code34"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> DisableDirtyFlag <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: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsDirty
    <span style="color: #008000;">&#123;</span>
        get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> isDirty<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        set
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>CanSetDirty<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                isDirty <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
&nbsp;
                OnPropertyChanged<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;IsDirty&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</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/2010/01/31/fgf-a-base-class-for-inotifypropertychanged/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('p532code36'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p53236"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p532code36"><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('p515code38'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p51538"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p515code38"><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>Provider Model &#8211; Design Pattern</title>
		<link>http://jsedlak.org/2009/12/15/provider-model-design-pattern/</link>
		<comments>http://jsedlak.org/2009/12/15/provider-model-design-pattern/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 06:28:34 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://jso.fg.com/?p=440</guid>
		<description><![CDATA[A design pattern made famous in the .NET community by Microsoft&#8217;s ASP.NET, the provider model explains is a pattern that supplies the end-developer with a plug-and-play architecture. The provider model is most often used when you have a consumer object that is dependent on specific functionality that can be supplied by one or more underlying [...]]]></description>
			<content:encoded><![CDATA[<p>A design pattern made famous in the .NET community by Microsoft&#8217;s ASP.NET, the provider model explains is a pattern that supplies the end-developer with a plug-and-play architecture. The provider model is most often used when you have a consumer object that is dependent on specific functionality that can be supplied by one or more underlying systems. The major benefit of which is an increase in manageability and reusability.</p>
<p><span id="more-440"></span></p>
<div class="Center"><img class="Bordered" src="/images/articles/design-patterns/provider-model-1.jpg" alt="Provider Model - UML"/></div>
<p>It is important to note that we identify, generalize and abstract key functionality from each specific implementation to a specification (an interface in C#) to guarantee the plug-and-play architecture. Consider a site that has one or more backend storage devices for user credentials. We want to iterate through them when a user attempts to login but hardcoding them creates a strong dependency on their specific implementations. This can cause maintenance issues later on as one or more devices are added or removed. To keep the site agile, we can use the provider model to abstract the credential verification process. Consider the following <i>provider specification</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('p440code44'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p44044"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p440code44"><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> IAuthenticationProvider<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">bool</span> CheckCredentials<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> username, <span style="color: #6666cc; font-weight: bold;">string</span> password<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>We can then implement this in many different ways, utilizing an SQL database, an Active Directory server or even a simple text check.</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('p440code45'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p44045"><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="p440code45"><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> SqlAuthenticationProvider <span style="color: #008000;">:</span> IAuthenticationProvider<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> CheckCredentials<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> username, <span style="color: #6666cc; font-weight: bold;">string</span> password<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>IsValid<span style="color: #008000;">&#40;</span>username, password<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// Run some SQL statement - set result to a bool</span>
        <span style="color: #6666cc; font-weight: bold;">bool</span> result <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">return</span> result<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;">class</span> TextAuthenticationProvider <span style="color: #008000;">:</span> IAuthenticationProvider<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> CheckCredentials<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> username, <span style="color: #6666cc; font-weight: bold;">string</span> password<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;">&#40;</span>username <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;root&quot;</span> <span style="color: #008000;">&amp;&amp;</span> password <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;hello&quot;</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>The beauty of this pattern is that as business requirements or APIs change, the core code of your application can remain unchanged. Instead you can update a configuration file, removing the need for recompilation and possibly a full 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('p440code46'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p44046"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p440code46"><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> LoginPage <span style="color: #008000;">:</span> Page<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Submit_Click<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>
        <span style="color: #0600FF; font-weight: bold;">foreach</span><span style="color: #008000;">&#40;</span>IAuthenticationProvider provider <span style="color: #0600FF; font-weight: bold;">in</span> Configuration<span style="color: #008000;">.</span><span style="color: #0000FF;">AuthenticationProviders</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>provider<span style="color: #008000;">.</span><span style="color: #0000FF;">CheckCredentials</span><span style="color: #008000;">&#40;</span>txtUsername<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span>, txtPassword<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</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;">// set some session variables or a cookie</span>
                Response<span style="color: #008000;">.</span><span style="color: #0000FF;">Redirect</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;UserProfile.aspx&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</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>I can hear you asking how this applies to game development and specifically the XNA universe. If you take a closer look at the XNA Framework you will find that this pattern is frequently used because of how flexible it is. For instance, any instance of <i>DrawableGameComponent</i> or <i>GameComponent</i> is a provider that implements some base interfaces. Similarly, any component you add to the services collection acts as a provider for anyone that consumes it.</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('p440code47'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p44047"><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="p440code47"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">namespace</span> Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">Xna</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Framework</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> IGameComponent<span style="color: #008000;">&#123;</span>
        <span style="color: #6666cc; font-weight: bold;">void</span> Initialize<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;">public</span> <span style="color: #6666cc; font-weight: bold;">interface</span> IDrawable<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 VisibleChanged<span style="color: #008000;">;</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;">;</span>
        <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;">bool</span> Visible <span style="color: #008000;">&#123;</span> get<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;">interface</span> IUpdateable<span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">event</span> EventHandler EnabledChanged<span style="color: #008000;">;</span>
        <span style="color: #0600FF; font-weight: bold;">event</span> EventHandler UpdateOrderChanged<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>
        <span style="color: #6666cc; font-weight: bold;">bool</span> Enabled <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>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The above specifications are then implemented by child classes that you have probably run into and used before. Mainly GameComponent implements IUpdateable and IGameComponent while DrawableGameComponent inherits the former and implements the IDrawable interface. We can say here that the component classes provide functionality to the Game class through the IGameComponent, IUpdateable, and IDrawable interfaces.</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('p440code48'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p44048"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p440code48"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">namespace</span> Microsoft<span style="color: #008000;">.</span><span style="color: #0000FF;">Xna</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Framework</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> GameComponent <span style="color: #008000;">:</span> IGameComponent, IUpdateable, IDisposable<span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// ...</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> DrawableGameComponent <span style="color: #008000;">:</span> GameComponent, IDrawable<span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// ...</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/12/15/provider-model-design-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FGF: A Helper For Creating Render Targets</title>
		<link>http://jsedlak.org/2009/11/25/a-helper-for-creating-render-targets/</link>
		<comments>http://jsedlak.org/2009/11/25/a-helper-for-creating-render-targets/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 12:48:04 +0000</pubDate>
		<dc:creator>John Sedlak</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[FGF]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://jsedlak.com/?p=259</guid>
		<description><![CDATA[Before I begin this post, big thanks to Eibx and David over at the Community Forums for helping me find these methods. I have modified the CheckTexture method a bit, but its purpose remains unchanged. As of the last FGF article, the Application class was implementing the IGame interface but was missing the ability to [...]]]></description>
			<content:encoded><![CDATA[<p>Before I begin this post, big thanks to Eibx and David over at the <a href="http://forums.xna.com/forums/p/43000/255276.aspx">Community Forums</a> for helping me find these methods. I have modified the CheckTexture method a bit, but its purpose remains unchanged.</p>
<p>As of the last FGF article, the Application class was implementing the IGame interface but was missing the ability to create a render target object on the PC and Xbox 360. For PC games this can be a troubling problem since different hardware can obviously require different formats and dimensions of render target. Rather than bake this functionality into the Application class itself, it is moved to a static helper class so that all developers can make good use of its functionality at any point in time.</p>
<p>To start off, a simple default creation method is included to give the basic functionality an easy access point.</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('p259code54'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25954"><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="p259code54"><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;">.</span><span style="color: #0000FF;">Graphics</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">class</span> GraphicsHelper
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> RenderTarget2D CreateRenderTarget<span style="color: #008000;">&#40;</span>GraphicsDevice device<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> CreateRenderTarget<span style="color: #008000;">&#40;</span>
                device, 
                device<span style="color: #008000;">.</span><span style="color: #0000FF;">PresentationParameters</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BackBufferWidth</span>, 
                device<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>, 
                device<span style="color: #008000;">.</span><span style="color: #0000FF;">PresentationParameters</span><span style="color: #008000;">.</span><span style="color: #0000FF;">BackBufferFormat</span>
            <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p><span id="more-259"></span></p>
<p>Secondly the real CreateRenderTarget method is revealed. It checks the device format as well as the multisample type to ensure that they are in accordance with what the hardware device requires.</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('p259code55'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25955"><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
</pre></td><td class="code" id="p259code55"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> RenderTarget2D CreateRenderTarget<span style="color: #008000;">&#40;</span>GraphicsDevice device, <span style="color: #6666cc; font-weight: bold;">int</span> width, <span style="color: #6666cc; font-weight: bold;">int</span> height, <span style="color: #6666cc; font-weight: bold;">int</span> levels, SurfaceFormat format<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            MultiSampleType sampleType <span style="color: #008000;">=</span> device<span style="color: #008000;">.</span><span style="color: #0000FF;">PresentationParameters</span><span style="color: #008000;">.</span><span style="color: #0000FF;">MultiSampleType</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>
                <span style="color: #008000;">!</span>GraphicsAdapter<span style="color: #008000;">.</span><span style="color: #0000FF;">DefaultAdapter</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CheckDeviceFormat</span><span style="color: #008000;">&#40;</span>
                    DeviceType<span style="color: #008000;">.</span><span style="color: #0000FF;">Hardware</span>, 
                    GraphicsAdapter<span style="color: #008000;">.</span><span style="color: #0000FF;">DefaultAdapter</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CurrentDisplayMode</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span>, 
                    TextureUsage<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span>, 
                    QueryUsages<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span>, 
                    ResourceType<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderTarget</span>, 
                    format
                <span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                format <span style="color: #008000;">=</span> device<span style="color: #008000;">.</span><span style="color: #0000FF;">DisplayMode</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</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>
                <span style="color: #008000;">!</span>GraphicsAdapter<span style="color: #008000;">.</span><span style="color: #0000FF;">DefaultAdapter</span><span style="color: #008000;">.</span><span style="color: #0000FF;">CheckDeviceMultiSampleType</span><span style="color: #008000;">&#40;</span>
                    DeviceType<span style="color: #008000;">.</span><span style="color: #0000FF;">Hardware</span>, 
                    format, 
                    device<span style="color: #008000;">.</span><span style="color: #0000FF;">PresentationParameters</span><span style="color: #008000;">.</span><span style="color: #0000FF;">IsFullScreen</span>, 
                    sampleType
                <span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                sampleType <span style="color: #008000;">=</span> MultiSampleType<span style="color: #008000;">.</span><span style="color: #0000FF;">None</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            CheckTextureSize<span style="color: #008000;">&#40;</span>width, height, <span style="color: #0600FF; font-weight: bold;">out</span> width, <span style="color: #0600FF; font-weight: bold;">out</span> height<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;">new</span> RenderTarget2D<span style="color: #008000;">&#40;</span>device, width, height, levels, format, sampleType, <span style="color: #FF0000;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>This method makes a call to the CheckTextureSize method which the <a href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.rendertarget2d.rendertarget2d.aspx">MSDN Documentation</a> is missing. Similar to the above method, the CheckTextureSize function checks the width and the height parameters against what the graphics adapter supports and, if necessary, changes each to comply with the requirements.</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('p259code56'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25956"><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
</pre></td><td class="code" id="p259code56"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> CheckTextureSize<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> width, <span style="color: #6666cc; font-weight: bold;">int</span> height, <span style="color: #0600FF; font-weight: bold;">out</span> <span style="color: #6666cc; font-weight: bold;">int</span> newWidth, <span style="color: #0600FF; font-weight: bold;">out</span> <span style="color: #6666cc; font-weight: bold;">int</span> newHeight<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #6666cc; font-weight: bold;">bool</span> returnValue <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
&nbsp;
            GraphicsDeviceCapabilities caps <span style="color: #008000;">=</span> GraphicsAdapter<span style="color: #008000;">.</span><span style="color: #0000FF;">DefaultAdapter</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetCapabilities</span><span style="color: #008000;">&#40;</span>DeviceType<span style="color: #008000;">.</span><span style="color: #0000FF;">Hardware</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>caps<span style="color: #008000;">.</span><span style="color: #0000FF;">TextureCapabilities</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RequiresPower2</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                returnValue <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// Perform a simple check before doing (possibly) unecessary math</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>IsPowerOfTwo<span style="color: #008000;">&#40;</span>width<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;">// Find the nearest base two log of the current width,</span>
                    <span style="color: #008080; font-style: italic;">// and go up to the next integer</span>
                    <span style="color: #6666cc; font-weight: bold;">double</span> exponent <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Ceiling</span><span style="color: #008000;">&#40;</span>Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span>width<span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                    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>Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Pow</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">2</span>, exponent<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;">// Perform a simple check before doing (possibly) unecessary math</span>
                <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>IsPowerOfTwo<span style="color: #008000;">&#40;</span>height<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;">// Find the nearest base two log of the current height,</span>
                    <span style="color: #008080; font-style: italic;">// and go up to the next integer</span>
                    <span style="color: #6666cc; font-weight: bold;">double</span> exponent <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Ceiling</span><span style="color: #008000;">&#40;</span>Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span>height<span style="color: #008000;">&#41;</span> <span style="color: #008000;">/</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Log</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                    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>Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Pow</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">2</span>, exponent<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;">if</span> <span style="color: #008000;">&#40;</span>caps<span style="color: #008000;">.</span><span style="color: #0000FF;">TextureCapabilities</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RequiresSquareOnly</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                returnValue <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">;</span>
&nbsp;
                width <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span>width, height<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                height <span style="color: #008000;">=</span> width<span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
&nbsp;
            newWidth <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Min</span><span style="color: #008000;">&#40;</span>caps<span style="color: #008000;">.</span><span style="color: #0000FF;">MaxTextureWidth</span>, width<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            newHeight <span style="color: #008000;">=</span> Math<span style="color: #008000;">.</span><span style="color: #0000FF;">Min</span><span style="color: #008000;">&#40;</span>caps<span style="color: #008000;">.</span><span style="color: #0000FF;">MaxTextureHeight</span>, height<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF; font-weight: bold;">return</span> returnValue<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The only real change I have introduced here is a simple check to see if the width and height are already powers of two before doing some possibly unecessary math. I decided to keep the check because it is extremely basic in terms of mathematical computation.</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('p259code57'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25957"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p259code57"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> IsPowerOfTwo<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> number<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;">&#40;</span>number <span style="color: #008000;">&amp;</span> <span style="color: #008000;">&#40;</span>number <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><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>And there you have it! A robust way for creating a render target on all the platforms that XNA supports. Now that we have this, the last change needs to happen in the Application class. Remember that ResetRenderTarget method? Well now it can be fixed up properly:</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('p259code58'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25958"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p259code58"><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> ResetRenderTarget<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>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> GraphicsHelper<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateRenderTarget</span><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: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://jsedlak.org/2009/11/25/a-helper-for-creating-render-targets/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('p256code73'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25673"><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="p256code73"><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('p256code74'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25674"><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="p256code74"><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('p256code75'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25675"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p256code75"><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('p256code76'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25676"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p256code76"><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('p256code77'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25677"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p256code77"><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('p256code78'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25678"><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="p256code78"><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('p256code79'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25679"><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="p256code79"><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('p256code80'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25680"><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="p256code80"><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('p256code81'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25681"><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="p256code81"><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('p256code82'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25682"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p256code82"><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('p256code83'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25683"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p256code83"><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('p256code84'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25684"><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="p256code84"><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('p256code85'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25685"><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="p256code85"><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('p256code86'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p25686"><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="p256code86"><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>
	</channel>
</rss>
