<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9</title>
    <atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Niners/rbarraza/Posts/RSS"></atom:link>
    <itunes:summary></itunes:summary>
    <itunes:author>Microsoft</itunes:author>
    <itunes:subtitle></itunes:subtitle>
    <image>
      <url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
      <title>Channel 9</title>
      <link>http://channel9.msdn.com/Niners/rbarraza/Posts</link>
    </image>
    <itunes:image href=""></itunes:image>
    <itunes:category text="Technology"></itunes:category>
    <description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
    <link>http://channel9.msdn.com/Niners/rbarraza/Posts</link>
    <language>en</language>
    <pubDate>Thu, 23 May 2013 19:14:27 GMT</pubDate>
    <lastBuildDate>Thu, 23 May 2013 19:14:27 GMT</lastBuildDate>
    <generator>Rev9</generator>
    <c9:totalResults>41</c9:totalResults>
    <c9:pageCount>2</c9:pageCount>
    <c9:pageSize>25</c9:pageSize>
  <item>
      <title>Getting started with Cinder for Windows Store Apps</title>
      <description><![CDATA[<h1>What is different on Windows 8</h1><p>Legacy software written for Windows 7 and prior targeted the traditional Windows API, often referred to as Win32. They resulting apps would be a combination of an executable, assets and libraries. The Windows 8 operating system introduces a new type of application, called a Windows Store app. The new architecture is called Windows Runtime, or WinRT for short. Windows Store apps are written exclusively against this new WinRT architecture.</p><p>Windows 7 and prior only had one mode of interacting with software, launching the application's executable from the desktop or file path. Windows 8 now defaults to a Windows Runtime start screen, where Windows Store apps are presented and can be accessed through their respective Live Tiles. An application's Live Tile is registered automatically when that app is installed from the Windows Store. If a user needs to access legacy software that hasn't been migrated to the new Windows Store format, they can still get to the desktop from the Start Screen.</p><p>Windows desktops and laptops have traditionally run on Intel processors, referred to frequently as x86 or x64 machines. However, in parallel with the release of Windows 8, an optimized version of the operating system designed for mobile ARM based devices was released called Windows RT. Windows RT devices, however, will not run legacy Win32 software, nor can you develop Win32 software for content.</p><p>So unlike a Windows 8 computer, which is optimized for the Windows Store apps written against WinRT but still provides access to Win32 software from the desktop, Windows RT devices do not.</p><h2>What about the Microsoft Surface?</h2><p>There are two versions of the Microsoft Surface. The first version runs the Windows RT operating system and uses an ARM CPU. The Surface Pro, however, is an x64 device and runs Windows Pro 8. Both devices are optimized for Windows Store apps, but the Surface Pro is a fully featured computer as well, allowing you to install Visual Studio, Photoshop, or whatever else you wish. You can think of the Microsoft Surface as a light, long lasting consumer consumption device, whereas the Surface Pro is a powerful, mobile content creation device and netbook equivalent.</p><h2>What's up with Cinder and DirectX?</h2><p>Cinder is a cross platform framework for C&#43;&#43; design engineering. In order to run and Apple, Android and Windows devices prior to Windows 8, the rendering libraries leveraged OpenGL as the open source, cross platform solution.</p><p>Even though DirectX has been Microsoft's preferred rendering solution for advanced graphics programming, Windows traditionally provided both DirectX and OpenGL support from the desktop. However, Windows 8 Store applications are now exclusively DirectX based, to maximize reusability across the entire domain of Microsoft experiences including Windows Phone, Windows RT, Windows 8, and gaming. This means that Cinder apps that leverage OpenGL for their rendering will not work as Windows Store apps.</p><p>To get a Cinder project running as a Windows Store app, the Cinder project needs to leverage a DirectX render instead of the default OpenGL renderer.</p><p>Both OpenGL and DirectX have undergone significant changes over the years, with DirectX migrating away from the simpler fixed function pipeline of OpenGL early on. As hardware and software continue to advance, both libraries continue to progress in their own distinct ways. Windows 8 Store apps leverage the most recent version of DirectX 11.1, which itself has some breaking changes from DirectX 11, most notably is the loss of D3DX, a very popular helper library.</p><p>As this document targets using Cinder for Windows Store apps, we will be using DirectX 11.1. Whereas you could have a DirectX renderer for desktop based Cinder experiences, because of the history and community support behind the existing OpenGL render, it would be a difficult choice to argue. However, to create a Windows Store app, DirectX 11.1 must be used as the underlying rendering technology in the Cinder framework.</p><h2>What about Visual Studio?</h2><p>Previous versions of Cinder were written to make it easy to use for Visual Studio 2010, and targeted Win32 applications. Since Windows Store apps require targeting the WinRT architecture, this has changed.</p><p>To develop software for Window Store 8, you need to use Visual Studio 2012. We will be walking through the setup assuming you have downloaded the free version of the software, Visual Studio Express 2012.</p><p>You should know, however ,that the professional versions of Visual Studio 2012 comes with several new features for professional graphics engineering, including a robust graphics debugger, DirectX support, visual shader editors, and tools for working with virtual models and objects.</p><h1>Enough theory, lets get started</h1><p>To create Windows Store apps, you need to have Windows 8 installed and running at least Visual Studio Express 2012 for Windows 8. Do not download Visual Studio Express 2012 for Web, Phone or Desktop. We are targeting Windows 8 here.</p><h2>Setting up Visual Studio Express 2012 for Windows 8</h2><p>Once you have a copy of Windows 8 running natively or on a virtual machine from another Operating System, you can get the bytes for Visual Express 2012 for Windows here:</p><p><a href="http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products">http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products</a></p><p>&nbsp;</p><p><img src="http://files.channel9.msdn.com/thumbnail/0048ca79-f2da-492e-9a3f-95c9702684b4.jpg" alt=""></p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p><p>When the installer has finished and you launch the application, you will be taken to a registration screen. If you choose not to register, Visual Studio Express 2012 will expire after 30 days. Go ahead and register the product.</p><p>&nbsp;</p><p><img src="http://files.channel9.msdn.com/thumbnail/a419c0e3-f757-42a9-9ec4-8e330bee7658.jpg" alt=""></p><p>&nbsp;</p><p>Once registration is complete, Visual Studio will launch for the first time. In order to create a Windows Store app, you need to setup a Developer license. A developer license allows you to develop, install and test apps on your computer before submitting them to the Microsoft store for publishing and deployment to the community.</p><p>At this time, it would also be a good idea to go to the menu item <em>Tools</em> &gt; <em>Extensions and Updates</em> and check for any updates to Visual Studio as well:</p><p>&nbsp;</p><p><img src="http://files.channel9.msdn.com/thumbnail/2705a27b-9cdd-4bf3-a381-49f4777946c2.jpg" alt=""></p><p>&nbsp;</p><h2>Grabbing the Git branch</h2><p>Now that we have Windows 8 and Visual Studio Express 2012 setup, our next step is getting the correct Cinder bits on our machine. Since this is still under development, we need to pull from the correct developer branch of Cinder from Cinder's GitHub account.</p><p>The professional version of Visual Studio 2012 allows for rich Git integration, but the free Express version doesn't support this, so you will need to have a standalone Git client if you choose to use the Express version of Visual Studio. If so, we recommend downloading the GitHub client, which installs both itself and helpful Git utilities.</p><p>You can download the GitHub client here:</p><p><a href="https://help.github.com/articles/set-up-git">https://help.github.com/articles/set-up-git</a></p><p>&nbsp;</p><p><img src="http://files.channel9.msdn.com/thumbnail/fe30b214-1c5d-4942-957c-2ba8f40133d9.jpg" alt=""></p><p>&nbsp;</p><p>After the GitHub client is installed, you may find it helpful to enter or setup your account. However, you should be able to pull the project if you just want to get up and running quickly using the Git Shell as explained further below.</p><p>As a community developed, open source project, Cinder separates the stable, official version of its Cinder framework from newer branches that developers setup as they program future functionality. WinRT support for Cinder is currently being developed off of one of these feature branches, with the goal of integrating in to a future iteration of the master project.</p><p>So we will need to clone the Cinder project locally, which defaults to the <strong><em>master</em></strong> branch, and then explicitly move to the <strong><em>dx_rt</em></strong> branch to get to the version under development that also includes support for Windows Store 8 projects.</p><p>To clone Cinder, either open your Git enabled Power Shell in the directory you want to use and type:</p><p>git clone <a href="https://github.com/cinder/Cinder.git">https://github.com/cinder/Cinder.git</a></p><p>&nbsp;</p><p>Or open a browser and go to the Cinder project page on GitHub.com. There you will see a<em> Clone In Windows </em>button that should launch the GitHub client automatically and start the local cloning process:</p><p><a href="https://github.com/cinder/Cinder/tree/dx_rt">https://github.com/cinder/Cinder/tree/dx_rt</a></p><p>&nbsp;</p><p>&nbsp;<img src="http://files.channel9.msdn.com/thumbnail/703d1546-6609-4d59-b020-d05a3f59b0df.jpg" alt="" width="640"></p><p>&nbsp;</p><p>This should take several minutes to download the Cinder project and open it in your GitHub client. Once it appears as a line item in your GitHub client, you can right click the repository icon and select open a shell here. We will do the rest of the commands from the Power Shell directly.</p><p>&nbsp;</p><p>If you look at your command prompt and you are still on the <strong><em>master</em></strong> branch, you can switch to the <strong><em>dx_rt</em></strong> branch by typing the following:</p><p>git checkout dx_rt</p><p>Or if you prefer to use the GitHub client you installed, you can switch from the master branch to the <strong><em>dx_rt</em></strong> branch from there as well.</p><p><img src="http://files.channel9.msdn.com/thumbnail/d65f1cfb-3968-485f-8d09-51dc76caff6e.jpg" alt="" width="640">&nbsp;</p><p>If you are using the GitHub client, though, it would probably be a good idea to switch to a command shell for the next steps. You can do that from the client directly by right clicking on project's list item like so:</p><p>&nbsp;</p><p><img src="http://files.channel9.msdn.com/thumbnail/460dcc05-2888-40e0-aae2-a1cea99d9239.jpg" alt="" width="640"></p><p>&nbsp;</p><p>The <strong><em>master</em></strong>, <strong><em>dev </em></strong>and <strong><em>dx_rt </em></strong>branches all require you to also install certain Boost libraries to the Cinder project directory before you can compile the Cinder framework. However, on the <strong><em>dx_rt</em></strong> branch we will be using, this process has been greatly automated for you. So once you've switched to the <strong><em>dx_rt </em></strong>branch, type in the following two commands to download the required Boost libraries that are compatible with this particular branch of Cinder for Windows Store:</p><p>git submodule init</p><p>git submodule update</p><p>This may take a few minutes, but once it is done you should be ready to open the Cinder project and compile it for use.</p><p>&nbsp;</p><h2>Compiling Cinder for Windows Store apps</h2><p>Once you have pulled the Cinder project from its GitHub repository, switched to the <strong><em>dx_rt</em></strong> branch that contains the bits for working on Windows Store apps, and run the submodules that download the additional Boost dependencies, you are ready to open up the Cinder solution to compile the library.</p><p>&nbsp;</p><p><img src="http://files.channel9.msdn.com/thumbnail/a66457b6-468f-4bf1-9519-a4529c3c7879.jpg" alt="" width="652">&nbsp;&nbsp;</p><p>&nbsp;</p><p>Go to where GitHub cloned the Cinder project, the default is <em>Libraries\Documents\GitHub\Cinder</em>. There you will find multiple version of the Cinder framework separated by development environment. You should see the xcode and vc10 solutions, but you will also three additional folders. Vc11 provides support for compiling Cinder for Visual Studio 2012, but still using OpenGL and thus limited to Desktop mode. VC11-DirectX is provides support for compiling Cinder for Visual Studio 2012 using DirectX 11 but also for Desktop mode. We will be focusing on the third option, the winrt folder. This is the solution that supports Windows Store apps and development.</p><p>Launch <em>Cinder/winrt/cinder.sln</em> and the Cinder project should open up in Visual Studio 2012 automatically. If you are using the professional version of Visual Studio 2012, you can Batch Build all the versions you need. Since we are using the Express edition in this walkthrough, though, we will Build individually the debug and release versions of the Cinder library we need.</p><p>We will build the debug version of the framework by making sure that our Solution Configuration in the toolbar is set to <em>Debug</em> and the Solution Platform is set to <em>Win32</em>.</p><p>&nbsp;</p><p><img src="http://files.channel9.msdn.com/thumbnail/82fa3597-f0e6-49d9-848e-de9aff315ceb.jpg" alt=""></p><p>&nbsp;</p><p>To build the solution, simply go to the Build menu option and select Build Solution.</p><p><img src="http://files.channel9.msdn.com/thumbnail/c52db37b-b8d4-4e16-bcfb-9c829b7f1f31.jpg" alt="">&nbsp;</p><p>&nbsp;</p><p>Some warnings may pop up, but there should be no errors. Once that is done, you will find a new file in the Cinder project directory under:</p><p><em>..\Cinder\lib\winrt\Win32\Debug\cinder.lib</em></p><p>This is the Cinder library your Windows Store projects will link to when you are programming and debugging your application. Now we need to rebuild this framework to provide a release version of this same framework. Going back to the Cinder project, and on the toolbar change the Solution Configuration option from Debug to Release and Build the solution again.</p><p>You now have a Debug and Release version of the Cinder framework and are ready to start creating Windows Store programs against it for any Windows 8 device, including the Surface Pro. However, any WindowsRT device, such as the non-Pro version of Surface, will be running on ARM and so you would need to follow the above steps targeting the ARM platform instead of just the Win32 platform.</p><h2>Testing out the Library</h2><p>At this point, you are ready to explore the collection of DirectX samples created specifically for Windows Store apps. You can find various projects for Windows Store in the DirectX folder inside the samples folder. For our initial test, we will open the following sample:</p><p><em>..\Cinder\samples\DirectX\_winrtBasic\winrt\winrtBasic.sln</em></p><p>When you open the solution in Visual Studio Express 2012, you will find basicApp.cpp in the Solution Explorer. This contains all the code we need to start using the Cinder framework.</p><p>&nbsp;</p><p><img src="http://files.channel9.msdn.com/thumbnail/504bbec1-6d8f-487c-b5fb-1199864a8535.jpg" alt=""></p><p>&nbsp;</p><p>The code in this sample illustrates a few basic tasks, including loading an image from the assets folder and using it as a texture, loading fonts and displaying them on the screen, handling mouse events, drawing various geometries and implementing a basic follower easing algorithm in the update() call.</p><p>Once you're looked over the code, you can press <strong>F5</strong> or the Play button on the main toolbar to run the program on the machine. If you compiled both the <strong><em>Debug</em></strong> and <strong><em>Release</em></strong> versions of the framework, you can select either Solution Configuration. <strong>You will find a significant increase in speed in <em>Release</em> mode over <em>Debug</em> mode</strong>.</p><p>&nbsp;</p><p><img src="http://files.channel9.msdn.com/thumbnail/65935f93-a608-4311-b598-782a209d4021.jpg" alt=""></p><p>&nbsp;</p><p>You will also notice that the program has automatically installed its own Live Tile on your Start Screen, which you can use to launch the program again whenever you wish.</p><p>&nbsp;</p><p><img src="http://files.channel9.msdn.com/thumbnail/73de0647-b976-43ac-bcba-e3db94dfa117.jpg" alt=""></p><p>&nbsp;</p><p>&nbsp;Congratulations! You should now be ready to start exploring Cinder for Windows Store apps.</p><p>&nbsp;</p><p>@rickbarraza</p><p>&nbsp;</p><p>You can learn more about this branch by going to the Cinder forums found here:</p><p><a href="https://forum.libcinder.org/#Topic/23286000001540037">https://forum.libcinder.org/#Topic/23286000001540037</a></p><p>&nbsp;</p><p>&nbsp;</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:27305f8a61ab4b7e8809a1be01440cfe">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Getting-started-with-Cinder-for-Windows-Store-Apps</comments>
      <itunes:summary>What is different on Windows 8Legacy software written for Windows 7 and prior targeted the traditional Windows API, often referred to as Win32. They resulting apps would be a combination of an executable, assets and libraries. The Windows 8 operating system introduces a new type of application, called a Windows Store app. The new architecture is called Windows Runtime, or WinRT for short. Windows Store apps are written exclusively against this new WinRT architecture. Windows 7 and prior only had one mode of interacting with software, launching the application&#39;s executable from the desktop or file path. Windows 8 now defaults to a Windows Runtime start screen, where Windows Store apps are presented and can be accessed through their respective Live Tiles. An application&#39;s Live Tile is registered automatically when that app is installed from the Windows Store. If a user needs to access legacy software that hasn&#39;t been migrated to the new Windows Store format, they can still get to the desktop from the Start Screen. Windows desktops and laptops have traditionally run on Intel processors, referred to frequently as x86 or x64 machines. However, in parallel with the release of Windows 8, an optimized version of the operating system designed for mobile ARM based devices was released called Windows RT. Windows RT devices, however, will not run legacy Win32 software, nor can you develop Win32 software for content. So unlike a Windows 8 computer, which is optimized for the Windows Store apps written against WinRT but still provides access to Win32 software from the desktop, Windows RT devices do not. What about the Microsoft Surface?There are two versions of the Microsoft Surface. The first version runs the Windows RT operating system and uses an ARM CPU. The Surface Pro, however, is an x64 device and runs Windows Pro 8. Both devices are optimized for Windows Store apps, but the Surface Pro is a fully featured computer as well, allowing you to install Visual Studio, Photoshop,</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Getting-started-with-Cinder-for-Windows-Store-Apps</link>
      <pubDate>Tue, 14 May 2013 22:20:52 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Getting-started-with-Cinder-for-Windows-Store-Apps</guid>
      <media:thumbnail url="http://files.channel9.msdn.com/thumbnail/2add242a-d78f-44df-8acf-85a42d25a7bd.jpg" height="220" width="220"></media:thumbnail>      
      <dc:creator>Rick Barraza</dc:creator>
      <itunes:author>Rick Barraza</itunes:author>
      <slash:comments>2</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Getting-started-with-Cinder-for-Windows-Store-Apps/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Introducing Creative Coding and ProcessingJS With Windows</title>
      <description><![CDATA[<p>Welcome to Creative Coding with ProcessingJS for Windows! In this series, our goal is to introduce people to the basics of using code to unleash their creative mind and give them the tools to create beautiful things with code. To this end, we've created some great tools and projects.</p><p><a href="http://processingjs.codeplex.com/"><img src="http://files.channel9.msdn.com/thumbnail/eef3492b-29c1-4619-94dd-900bb3ecd825.png" alt=""></a><a href="http://apps.microsoft.com/windows/app/processing-for-windows/27e8a073-f881-45fc-b887-ef739ed7095a"><img src="http://files.channel9.msdn.com/thumbnail/ab28038f-dca1-4275-84e6-d48b37033176.png" alt=""></a><a href="http://www.windowsphone.com/s?appid=734ea3b3-d4db-46c3-b46c-45131fb748af"><img src="http://files.channel9.msdn.com/thumbnail/1130b603-a2e8-46d0-9c81-9e124b9e2b5d.png" alt=""></a></p><p><strong><a href="http://processingjs.codeplex.com/">ProcessingJS Sketchbooks on Codeplex </a></strong>- Open source starter projects for writing full screen apps using ProcessingJS. We've included a ProcessingJS implementation&nbsp;for Windows 8&nbsp;in&nbsp;both&nbsp;C# and JavaScript and another for Windows Phone. ProcessingJS Template for Windows Phone - Want to write a Windows Phone app in ProcessingJS? Install this template and start as many ProcessingJS Windows Phone projects as you want.</p><p><strong>Creative Coding video series</strong> - a creative coding lesson plan taught by Rick Barraza and Matthias Shapiro (links below).</p><p><a href="http://apps.microsoft.com/windows/app/processing-for-windows/27e8a073-f881-45fc-b887-ef739ed7095a"><strong>ProcessingJS for Windows</strong></a> - a micro-IDE in the Windows Store that allows users to write, view and export ProcessingJS sketches.</p><p><a href="http://www.windowsphone.com/s?appid=734ea3b3-d4db-46c3-b46c-45131fb748af"><strong>ProcessingJS Reader for Windows Phone</strong></a> - view your ProcessingJS sketches on your Windows Phone. Share sketches by emailing them or sharing them via NFC. Available in the Windows Phone Marketplace.</p><p>As an introduction to the series, we'll break it down into three parts before walking through all the tools we're releasing to help you create your own unique visuals.</p><p><strong>Creative Coding</strong></p><p>Have you ever looked at some beautiful programmatic animation, visualization, or interaction and wondered how it was done (or wished you could do that yourself)? This is the drive behind the Creative Coding series.</p><p>We've put together a set of 10 videos that will walk you through some of the essential skills and techniques necessary to create responsive and beautiful interactive visuals. The videos build upon one another so watch them in order to get the most out of the series.</p><p><strong>Topics covered</strong></p><ul><li><a href="http://channel9.msdn.com/Series/Sketchbooktutorial/Setting-up-your-Windows-8-environment">Getting Started in ProcessingJS </a>- programming a bouncing ball </li><li><a href="http://channel9.msdn.com/Series/Sketchbooktutorial/Particles-Classes-and-Color">Simple Particles</a>&nbsp; - random motion </li><li><a href="http://channel9.msdn.com/Series/Sketchbooktutorial/Jelly-Blobs-Easing-and-Elastic">Jelly Blobs</a> - easing and elastic motion </li><li><a href="http://channel9.msdn.com/Series/Sketchbooktutorial/Drawing-with-Emitters">Simple Emitter</a> - animation queues and life cycles </li><li><a href="http://channel9.msdn.com/Series/Sketchbooktutorial/Trigonometry-for-Designers-Dont-Panic">Fibonacci Flowers</a> - trigonometry in design </li><li><a href="http://channel9.msdn.com/Series/Sketchbooktutorial/Grids-Direction-and-Rotation">Direction and Rotation</a> - tangents and rotation </li><li><a href="http://channel9.msdn.com/Series/Sketchbooktutorial/Text-Pens-and-Multi-Touch">Mouse, Pen, Fingers</a> - multi touch interactions </li><li><a href="http://channel9.msdn.com/Series/Sketchbooktutorial/Simple-Collision-Detection-and-Response">Collision and Bounce</a> - programming angled collisions </li><li><a href="http://channel9.msdn.com/Series/Sketchbooktutorial/Loading-Images-and-Generative-Art">Working with Images</a> - loading graphics and recursion </li><li><a href="http://media.ch9.ms/ch9/761e/9c114521-c571-4dc2-bff2-ecb20d59761e/PJSphoneIntro.mp4">ProcessingJS and Windows Phone </a>- getting your sketch on your Windows Phone </li></ul><p><strong>With ProcessingJS</strong></p><p>For our coding environment, we wanted to use a technology that would make our projects as accessible as possible. We ultimately decided to use ProcessingJS, which is a web-compatible implementation of the Processing visual programming language. ProcessingJS is a simple but powerful library for visual programming that uses the HTML5 canvas as the drawing board for data visualizations, digital art, interactive animations and even games.</p><p>ProcessingJS sketches can get people started with a single line of code. For example:</p><p><pre class="brush: text">ellipse(100,100, 20, 20);</pre></p><p>is a valid ProcessingJS sketch that draws a 20 pixel diameter ellipse at&nbsp;the (100,100)&nbsp;x,y coordinate on a default sketch canvas.</p><p>But we can also write sketches that use a draw loop to create iterative visuals. Or we could write event based sketches that update or react base on interactive events (like mouse or touch).&nbsp;By combining these programming and visual elements, we can create some beautiful sketches by just layering these simple concepts. This makes ProcessingJS perfect as platform for learning creative coding.</p><p><a href="http://processingjs.org/reference/">ProcessingJS Reference</a></p><p><a href="https://github.com/processing-js/processing-js/">ProcessingJS Source Github</a></p><p><strong>For Windows (and Windows Phone)</strong></p><p>These projects and apps are designed to take advantage of the Windows and Windows Phone platforms. Because of this, we've made a few updates to the ProcessingJS library. In the Windows Store app, the entire application is written in HTML5, so integrating a JavaScript library to that was no problem at all for most ProcessingJS sketches. But when it came time to implement multi-touch interactions, we found that we needed to add support for pointer events to ProcessingJS.</p><p>Pointer events are what Internet Explorer 10 uses to detect any pointer interaction, which covers mouse, stylus and touch interaction. It is currently (as of March 21, 2013) a W3C working draft an intended to become&nbsp;the W3C recommendations for touch interaction standards.&nbsp;But the nicest thing about (at least for this project) is that IE10 in on both Windows 8 and Windows Phone 8 so we can take the same pointer-enabled ProcessingJS library, do nothing to it and know that our sketches will work in Windows Phone.</p><p>And we've designed for this. If you're building a ProcessingJS sketch in the Windows Store app, you can export it as a file and simply attach it in an email and you or your friends can launch that sketch in directly from the email app in your Windows Phone (Windows Phone 8 is required). This way you can create and share apps across Windows 8 and Windows Phone 8 using apps freely available in the Stores.</p><p>If you want to move beyond that and use ProcessingJS to create full Windows 8 and Windows Phone 8 apps, go to our ProcessingJS Codeplex and download the projects and templates there. Using these projects and templates, you can build full-screen ProcessingJS apps for both platforms. We even have a Windows Phone 8 template that you can install and just have a ProcessingJS enabled project ready to go anytime.</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:fc041e0496624412ab80a187016bb695">]]></description>
      <comments>http://channel9.msdn.com/Series/Sketchbooktutorial/Introducing-Creative-Coding-and-ProcessingJS-With-Windows</comments>
      <itunes:summary>Welcome to Creative Coding with ProcessingJS for Windows! In this series, our goal is to introduce people to the basics of using code to unleash their creative mind and give them the tools to create beautiful things with code. To this end, we&#39;ve created some great tools and projects.  ProcessingJS Sketchbooks on Codeplex - Open source starter projects for writing full screen apps using ProcessingJS. We&#39;ve included a ProcessingJS implementation&amp;nbsp;for Windows 8&amp;nbsp;in&amp;nbsp;both&amp;nbsp;C# and JavaScript and another for Windows Phone. ProcessingJS Template for Windows Phone - Want to write a Windows Phone app in ProcessingJS? Install this template and start as many ProcessingJS Windows Phone projects as you want. Creative Coding video series - a creative coding lesson plan taught by Rick Barraza and Matthias Shapiro (links below). ProcessingJS for Windows - a micro-IDE in the Windows Store that allows users to write, view and export ProcessingJS sketches. ProcessingJS Reader for Windows Phone - view your ProcessingJS sketches on your Windows Phone. Share sketches by emailing them or sharing them via NFC. Available in the Windows Phone Marketplace. As an introduction to the series, we&#39;ll break it down into three parts before walking through all the tools we&#39;re releasing to help you create your own unique visuals. Creative Coding Have you ever looked at some beautiful programmatic animation, visualization, or interaction and wondered how it was done (or wished you could do that yourself)? This is the drive behind the Creative Coding series. We&#39;ve put together a set of 10 videos that will walk you through some of the essential skills and techniques necessary to create responsive and beautiful interactive visuals. The videos build upon one another so watch them in order to get the most out of the series. Topics covered Getting Started in ProcessingJS - programming a bouncing ball Simple Particles&amp;nbsp; - random motion Jelly Blobs - easing and elastic motion Simple Emitter</itunes:summary>
      <link>http://channel9.msdn.com/Series/Sketchbooktutorial/Introducing-Creative-Coding-and-ProcessingJS-With-Windows</link>
      <pubDate>Wed, 24 Apr 2013 17:58:39 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Series/Sketchbooktutorial/Introducing-Creative-Coding-and-ProcessingJS-With-Windows</guid>
      <media:thumbnail url="http://files.channel9.msdn.com/thumbnail/1e0188a4-c210-4fb1-b514-1ec2f7d4991b.jpg" height="63" width="100"></media:thumbnail>
      <media:thumbnail url="http://files.channel9.msdn.com/thumbnail/c809d5d8-1f39-4dc3-8423-6cc67d8f56b9.jpg" height="139" width="220"></media:thumbnail>
      <media:thumbnail url="http://files.channel9.msdn.com/thumbnail/4d09840d-af61-4d85-a151-11b99e99e4e5.jpg" height="288" width="512"></media:thumbnail>      
      <dc:creator>Clint Rutkas, Matthias Shapiro, Rick Barraza</dc:creator>
      <itunes:author>Clint Rutkas, Matthias Shapiro, Rick Barraza</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Series/Sketchbooktutorial/Introducing-Creative-Coding-and-ProcessingJS-With-Windows/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Loading Images and Generative Art</title>
      <description><![CDATA[<p><a href="http://media.ch9.ms/coding4fun/processingjs/images.html">See images and generative art sketch in action</a></p><p>In this lesson, we look at loading external image files and painting them into our sketch. We also start glitching our logic and play with some simple recursive principles by tweaking PushMatrix() and PopMatrix().</p><p>To follow along in Visual Studio, please <a href="https://processingjs.codeplex.com/releases/view/106003">download the Processing Sketchbook projection.</a></p><p>The finished sketch for this lesson can be found below:</p><p><pre class="brush: js">
ArrayList bladeImages = new ArrayList();
totalBlades = 12;
Blade[] blades = new Blade[totalBlades];
float targetX, targetY;
float pointerX, pointerY;
float dx, dy;
int width, height;
 
void setup() {
    width = 500;
    height = 550;
    size(width, height);
    noStroke();
    smooth();
    targetX = width / 2;
    targetY = height / 2;
    bladeImages[0] = loadImage(&quot;images/blade1.png&quot;);
    bladeImages[1] = loadImage(&quot;images/blade2.png&quot;);
    for (int i = 0; i &lt; totalBlades; i&#43;&#43;) {
       Blade blade = new Blade();
       blade.x = width/2;
       blade.y = height/2;
       blade.index = i;
       blade.rotation = i/2;
       blades[i] = blade;
    }
};
 
void draw() {
    dx &#43;= ( targetX - pointerX) * .2; 
    dy &#43;= ( targetY - pointerY) * .2;
    dx *= .93;  dy *= .93;
    pointerX &#43;= dx;
    pointerY &#43;= dy;
    fill(color(16, 46, 16, 10));
    rect(0,0,width, height);
    for ( int i = 0; i &lt; totalBlades; i&#43;&#43;)  {
      pushMatrix();
      translate(pointerX, pointerY);
      rotate(blades[i].rotation);
      for ( int c = 0; c &lt; 20; c&#43;&#43;)    {
        blades[i].growth = c &#43; .3*(dx&#43;dy);
        blades[i].index&#43;&#43;;  
        blades[i].render();
      }
      popMatrix();  
    }
};
 
void pointerMove(TouchEvent e) {
  targetX = e.offsetX;
  targetY = e.offsetY;
};
 
class Blade {
  float x = 0;
  float y = 0;
  float growth = 0.0;
  float rotation = 0.0;
  int index = 0;
 
  void render() {
    scale(0.8, 0.8);
    translate(5*this.growth, 0);
    rotate(this.growth);
    image(bladeImages[this.index%2], this.growth * 5, this.growth);
   }
}
</pre></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:ee90b3127b0b42118825a157012b43ae">]]></description>
      <comments>http://channel9.msdn.com/Series/Sketchbooktutorial/Loading-Images-and-Generative-Art</comments>
      <itunes:summary>See images and generative art sketch in action In this lesson, we look at loading external image files and painting them into our sketch. We also start glitching our logic and play with some simple recursive principles by tweaking PushMatrix() and PopMatrix(). To follow along in Visual Studio, please download the Processing Sketchbook projection. The finished sketch for this lesson can be found below: 
ArrayList bladeImages = new ArrayList();
totalBlades = 12;
Blade[] blades = new Blade[totalBlades];
float targetX, targetY;
float pointerX, pointerY;
float dx, dy;
int width, height;
 
void setup() {
    width = 500;
    height = 550;
    size(width, height);
    noStroke();
    smooth();
    targetX = width / 2;
    targetY = height / 2;
    bladeImages[0] = loadImage(&amp;quot;images/blade1.png&amp;quot;);
    bladeImages[1] = loadImage(&amp;quot;images/blade2.png&amp;quot;);
    for (int i = 0; i &amp;lt; totalBlades; i&amp;#43;&amp;#43;) {
       Blade blade = new Blade();
       blade.x = width/2;
       blade.y = height/2;
       blade.index = i;
       blade.rotation = i/2;
       blades[i] = blade;
    }
};
 
void draw() {
    dx &amp;#43;= ( targetX - pointerX) * .2; 
    dy &amp;#43;= ( targetY - pointerY) * .2;
    dx *= .93;  dy *= .93;
    pointerX &amp;#43;= dx;
    pointerY &amp;#43;= dy;
    fill(color(16, 46, 16, 10));
    rect(0,0,width, height);
    for ( int i = 0; i &amp;lt; totalBlades; i&amp;#43;&amp;#43;)  {
      pushMatrix();
      translate(pointerX, pointerY);
      rotate(blades[i].rotation);
      for ( int c = 0; c &amp;lt; 20; c&amp;#43;&amp;#43;)    {
        blades[i].growth = c &amp;#43; .3*(dx&amp;#43;dy);
        blades[i].index&amp;#43;&amp;#43;;  
        blades[i].render();
      }
      popMatrix();  
    }
};
 
void pointerMove(TouchEvent e) {
  targetX = e.offsetX;
  targetY = e.offsetY;
};
 
class Blade {
  float x = 0;
  float y = 0;
  float growth = 0.0;
  float rotation = 0.0;
  int index = 0;
 
  void render() {
    scale(0.8, 0.8);
    tra</itunes:summary>
      <itunes:duration>2361</itunes:duration>
      <link>http://channel9.msdn.com/Series/Sketchbooktutorial/Loading-Images-and-Generative-Art</link>
      <pubDate>Mon, 22 Apr 2013 21:17:44 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Series/Sketchbooktutorial/Loading-Images-and-Generative-Art</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/65df/55fbb518-6850-4dce-b6ce-e21f375065df/SketchbookTutorial9_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/65df/55fbb518-6850-4dce-b6ce-e21f375065df/SketchbookTutorial9_220.jpg" height="123" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/65df/55fbb518-6850-4dce-b6ce-e21f375065df/SketchbookTutorial9_512.jpg" height="288" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://media.ch9.ms/ch9/65df/55fbb518-6850-4dce-b6ce-e21f375065df/SketchbookTutorial9.mp3" expression="full" duration="2361" fileSize="37792684" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/65df/55fbb518-6850-4dce-b6ce-e21f375065df/SketchbookTutorial9.mp4" expression="full" duration="2361" fileSize="230088938" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/65df/55fbb518-6850-4dce-b6ce-e21f375065df/SketchbookTutorial9.webm" expression="full" duration="2361" fileSize="74956354" type="video/webm" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/65df/55fbb518-6850-4dce-b6ce-e21f375065df/SketchbookTutorial9.wma" expression="full" duration="2361" fileSize="19104463" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/65df/55fbb518-6850-4dce-b6ce-e21f375065df/SketchbookTutorial9.wmv" expression="full" duration="2361" fileSize="99729131" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/65df/55fbb518-6850-4dce-b6ce-e21f375065df/SketchbookTutorial9_high.mp4" expression="full" duration="2361" fileSize="506497979" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/65df/55fbb518-6850-4dce-b6ce-e21f375065df/SketchbookTutorial9_mid.mp4" expression="full" duration="2361" fileSize="353544521" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/65df/55fbb518-6850-4dce-b6ce-e21f375065df/SketchbookTutorial9_Source.wmv" expression="full" duration="2361" fileSize="230186982" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/65df/55fbb518-6850-4dce-b6ce-e21f375065df/SketchbookTutorial9.ism/manifest" expression="full" duration="2361" fileSize="6106" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://media.ch9.ms/ch9/65df/55fbb518-6850-4dce-b6ce-e21f375065df/SketchbookTutorial9.wmv" length="99729131" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Rick Barraza</dc:creator>
      <itunes:author>Rick Barraza</itunes:author>
      <slash:comments>2</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Series/Sketchbooktutorial/Loading-Images-and-Generative-Art/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Simple Collision Detection and Response</title>
      <description><![CDATA[<p><a href="http://media.ch9.ms/coding4fun/processingjs/collisions.html">See collision detection sketch in action</a>&nbsp;</p><p>We expand on our basic particles sketch to include collision detection and handling an appropriate response. We break out the white board again to explain the physics and math involved before jumping into code.</p><p>To follow along in Visual Studio, please <a href="https://processingjs.codeplex.com/releases/view/106003">download the Processing Sketchbook projection.</a></p><p>The finished sketch for this lesson can be found below:</p><p><pre class="brush: js">
int totalBalls = 16;
Ball[] balls = new Ball[totalBalls];
float targetX, targetY;
int width, height;
 
void setup() {
    width = 500;
    height = 550;
    size(width, height);
    noStroke();
    smooth();
    background(0);
    targetX = width / 2;
    targetY = height / 2;
    fill(color(255, 0, 0));
    for (int i = 0; i &lt; totalBalls; i&#43;&#43;) {
        Ball ball = new Ball();
        ball.x = random(width);
        ball.y = random(height);
        ball.vx = random(10) - 5;
        ball.vy = random(10) - 5;
        ball.radius = width * .05;
        balls[i] = ball;
    }
};
 
void draw() {
    background(0);
    fill(color(255, 0, 0));
    for (int i = 0; i &lt; totalBalls; i&#43;&#43;) {
        balls[i].x &#43;= balls[i].vx;
        balls[i].y &#43;= balls[i].vy;
        checkWallCollision(balls[i]);
        balls[i].render();
    }
    for (int i = 0; i &lt; totalBalls; i&#43;&#43;) {
        for (int j = i &#43; 1; j &lt; totalBalls; j&#43;&#43;) {
            float dx = balls[j].x - balls[i].x;
            float dy = balls[j].y - balls[i].y;
            float dist = sqrt(dx * dx &#43; dy * dy);
            if (dist &lt; (balls[j].radius &#43; balls[i].radius)) {
                // balls have contact so push back...
                float normalX = dx / dist;
                float normalY = dy / dist;
                float midpointX = (balls[i].x &#43; balls[j].x) / 2;
                float midpointY = (balls[i].y &#43; balls[j].y) / 2;
                balls[i].x = midpointX - normalX * balls[i].radius;
                balls[i].y = midpointY - normalY * balls[i].radius;
                balls[j].x = midpointX &#43; normalX * balls[j].radius;
                balls[j].y = midpointY &#43; normalY * balls[j].radius;
                float dVector = (balls[i].vx - balls[j].vx) * normalX;
                dVector &#43;= (balls[i].vy - balls[j].vy) * normalY;
                float dvx = dVector * normalX;
                float dvy = dVector * normalY;
                balls[i].vx -= dvx;
                balls[i].vy -= dvy;
                balls[j].vx &#43;= dvx;
                balls[j].vy &#43;= dvy;
            }
        }
    }
};
 
void checkWallCollision(Ball ball) {
    if (ball.x &lt; ball.radius) {
        ball.x = ball.radius;
        ball.vx *= -1;
    }     if (ball.x &gt; width - (ball.radius)) {
        ball.x = width - (ball.radius);
        ball.vx *= -1;
    }     if (ball.y &lt; ball.radius) {
        ball.y = ball.radius;
        ball.vy *= -1;
    }     if (ball.y &gt; height - (ball.radius)) {
        ball.y = height - (ball.radius);
        ball.vy *= -1;
    }
}
 
class Ball {
  float x = 0;
  float y = 0;
  float vx = 0;
  float vy = 0;
  float gravityX = 0;
  float gravityY = 0;
  float radius = 5.0;
 
  void render() {
      ellipse(this.x, this.y, this.radius * 2, this.radius * 2);
  }
}
</pre></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:8c55d0ad00cc4dce99b0a157012b0b97">]]></description>
      <comments>http://channel9.msdn.com/Series/Sketchbooktutorial/Simple-Collision-Detection-and-Response</comments>
      <itunes:summary>See collision detection sketch in action&amp;nbsp; We expand on our basic particles sketch to include collision detection and handling an appropriate response. We break out the white board again to explain the physics and math involved before jumping into code. To follow along in Visual Studio, please download the Processing Sketchbook projection. The finished sketch for this lesson can be found below: 
int totalBalls = 16;
Ball[] balls = new Ball[totalBalls];
float targetX, targetY;
int width, height;
 
void setup() {
    width = 500;
    height = 550;
    size(width, height);
    noStroke();
    smooth();
    background(0);
    targetX = width / 2;
    targetY = height / 2;
    fill(color(255, 0, 0));
    for (int i = 0; i &amp;lt; totalBalls; i&amp;#43;&amp;#43;) {
        Ball ball = new Ball();
        ball.x = random(width);
        ball.y = random(height);
        ball.vx = random(10) - 5;
        ball.vy = random(10) - 5;
        ball.radius = width * .05;
        balls[i] = ball;
    }
};
 
void draw() {
    background(0);
    fill(color(255, 0, 0));
    for (int i = 0; i &amp;lt; totalBalls; i&amp;#43;&amp;#43;) {
        balls[i].x &amp;#43;= balls[i].vx;
        balls[i].y &amp;#43;= balls[i].vy;
        checkWallCollision(balls[i]);
        balls[i].render();
    }
    for (int i = 0; i &amp;lt; totalBalls; i&amp;#43;&amp;#43;) {
        for (int j = i &amp;#43; 1; j &amp;lt; totalBalls; j&amp;#43;&amp;#43;) {
            float dx = balls[j].x - balls[i].x;
            float dy = balls[j].y - balls[i].y;
            float dist = sqrt(dx * dx &amp;#43; dy * dy);
            if (dist &amp;lt; (balls[j].radius &amp;#43; balls[i].radius)) {
                // balls have contact so push back...
                float normalX = dx / dist;
                float normalY = dy / dist;
                float midpointX = (balls[i].x &amp;#43; balls[j].x) / 2;
                float midpointY = (balls[i].y &amp;#43; balls[j].y) / 2;
                balls[i].x = midpointX - normalX * balls[i].radius;
    </itunes:summary>
      <itunes:duration>2192</itunes:duration>
      <link>http://channel9.msdn.com/Series/Sketchbooktutorial/Simple-Collision-Detection-and-Response</link>
      <pubDate>Mon, 22 Apr 2013 21:17:37 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Series/Sketchbooktutorial/Simple-Collision-Detection-and-Response</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/1f25/3fa726c9-ed3f-4e83-9e03-7b0df5c41f25/SketchbookTutorial8_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/1f25/3fa726c9-ed3f-4e83-9e03-7b0df5c41f25/SketchbookTutorial8_220.jpg" height="123" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/1f25/3fa726c9-ed3f-4e83-9e03-7b0df5c41f25/SketchbookTutorial8_512.jpg" height="288" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://media.ch9.ms/ch9/1f25/3fa726c9-ed3f-4e83-9e03-7b0df5c41f25/SketchbookTutorial8.mp3" expression="full" duration="2192" fileSize="35079711" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/1f25/3fa726c9-ed3f-4e83-9e03-7b0df5c41f25/SketchbookTutorial8.mp4" expression="full" duration="2192" fileSize="214639840" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/1f25/3fa726c9-ed3f-4e83-9e03-7b0df5c41f25/SketchbookTutorial8.webm" expression="full" duration="2192" fileSize="72106066" type="video/webm" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/1f25/3fa726c9-ed3f-4e83-9e03-7b0df5c41f25/SketchbookTutorial8.wma" expression="full" duration="2192" fileSize="17734639" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/1f25/3fa726c9-ed3f-4e83-9e03-7b0df5c41f25/SketchbookTutorial8.wmv" expression="full" duration="2192" fileSize="119634173" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/1f25/3fa726c9-ed3f-4e83-9e03-7b0df5c41f25/SketchbookTutorial8_high.mp4" expression="full" duration="2192" fileSize="469915659" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/1f25/3fa726c9-ed3f-4e83-9e03-7b0df5c41f25/SketchbookTutorial8_mid.mp4" expression="full" duration="2192" fileSize="328212357" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/1f25/3fa726c9-ed3f-4e83-9e03-7b0df5c41f25/SketchbookTutorial8_Source.wmv" expression="full" duration="2192" fileSize="256611006" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/1f25/3fa726c9-ed3f-4e83-9e03-7b0df5c41f25/SketchbookTutorial8.ism/manifest" expression="full" duration="2192" fileSize="6106" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://media.ch9.ms/ch9/1f25/3fa726c9-ed3f-4e83-9e03-7b0df5c41f25/SketchbookTutorial8.wmv" length="119634173" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Rick Barraza</dc:creator>
      <itunes:author>Rick Barraza</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Series/Sketchbooktutorial/Simple-Collision-Detection-and-Response/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Text, Pens and Multi-Touch</title>
      <description><![CDATA[<p><a href="http://media.ch9.ms/coding4fun/processingjs/pointers.html">See pointers and multi-touch sketches in action</a>&nbsp;</p><p>Windows 8 Store applications support a robust set of Pointer types, including finger tracking, input stylus and traditional mouse events. By expanding on some basic functionality, we can leverage these new Pointer events in our Processing.JS sketch and show how to differentiate between simultaneous and differentiated inputs. We'll also introduce adding basic text to your sketches.</p><p>To follow along in Visual Studio, please <a href="https://processingjs.codeplex.com/releases/view/106003">download the Processing Sketchbook projection.</a></p><p>The finished sketch for this lesson can be found below:</p><p><pre class="brush: js">
ArrayList pointers = new ArrayList();
int width, height;
String txtOutput;
void setup() {
    width = 500;
    height = 550;
    size(width, height);
    smooth();
    background(0);
    fill(color(255, 255, 255));
    PFont arial = loadFont(&quot;arial&quot;);
     textFont(arial, 14);
}
 
void draw() {
    fill(color(0, 0, 0, 20));
    noStroke();
    rect(0, 0, width, height);
    txtOutput = pointers.size() &#43; &quot;:&quot;;
    for(int i = 0; i &lt; pointers.size(); i&#43;&#43;){
      Pointer p = (Pointer)pointers.get(i);
      stroke(p.pColor);
      strokeWeight(p.size);
      txtOutput &#43;= p.description;
      switch ( p.description) {
        case &quot;mouse&quot;:
        case &quot;pen&quot;:
          line(p.oldX, p.oldY, p.x, p.y);
          p.oldX = p.x;
          p.oldY = p.y;
          break;
        case &quot;touch&quot;:
          for (int currentLine = 0; currentLine &lt; 4; currentLine&#43;&#43;) {
            PointLine pLine = p.lines[currentLine];
            line(pLine.x1, pLine.y1, pLine.x2, pLine.y2);
          }
         updateLines(p);
         break;
       }
    }
    fill(color(255,255,255,255));
    text(txtOutput, 30, 30);
}
 
void pointerDown(TouchEvent e){
    Pointer p = new Pointer();
    p.x = e.offsetX;
    p.y = e.offsetY;
    p.oldX = e.offsetX;
    p.oldY = e.offsetY;
    p.id = e.pointerId;
    switch (e.pointerType) {
        case e.MSPOINTER_TYPE_MOUSE:
            p.pColor = color(255, 255, 255);
            p.size = 4.0;
            p.description = &quot;mouse&quot;;
            break;
        case e.MSPOINTER_TYPE_PEN:
            p.pColor = color(0, 255, 0);
            p.size = 1.0;
            p.description = &quot;pen&quot;;
            break;
        case e.MSPOINTER_TYPE_TOUCH:
            float r = map(e.offsetX, 0, width, 0, 255);
            float g = map(e.offsetY, 0, height, 0, 255);
            p.pColor = color(r, g, 255-r);
            p.size = 2.0;
            p.description = &quot;touch&quot;;
            addLines(p);
            break;
    }
    pointers.add(p);
}
 
void addLines(Pointer _pointer) {
  _pointer.lines[0] = new PointLine(_pointer.x, _pointer.y, 0, height*.5);
  _pointer.lines[1] = new PointLine(_pointer.x, _pointer.y, width, height * .5);
  _pointer.lines[2] = new PointLine(_pointer.x, _pointer.y, width * .5, 0);
  _pointer.lines[3] = new PointLine(_pointer.x, _pointer.y, width * .5, height);
}
 
void updateLines(Pointer _pointer) {
  for (int i = 0; i &lt; 4; i&#43;&#43;) {
      _pointer.lines[i].x1 = _pointer.x;
      _pointer.lines[i].y1 = _pointer.y;
  }
}
 
void pointerMove(Pointer e) {
  Pointer heldPointer;
  boolean hasPointer = false;
  int holderPos = -1;
  for(int i = pointers.size()-1; i &gt;=0; i--){
    Pointer p = (Pointer)pointers.get(i);
    if(p.id == e.pointerId){
      heldPointer = p;
      pointers.remove(i);
      holderPos = i;
      hasPointer = true;
    }
  }
  if(hasPointer &amp;&amp; holderPos != -1)  {
    heldPointer.x = e.offsetX;
    heldPointer.y = e.offsetY;
    pointers.add(heldPointer);
  }
}
 
void pointerUp(Pointer e) {  removePointer(e.pointerId);  }
 
void pointerCancel(TouchEvent e) {  removePointer(e.pointerId); }
 
void pointerOut(TouchEvent e) {  removePointer(e.pointerId); }
 
void removePointer(float pID) {
  for(int i = pointers.size()-1; i &gt;=0; i--){
    Pointer holderPointer = (Pointer)pointers.get(i);
    if(holderPointer.id == pID){
      pointers.remove(i);
    }
  }
}
 
class Pointer {
    float x = 0.0;
    float y = 0.0;
    float oldX = 0.0;
    float oldY = 0.0;
    color pColor = color(255, 255, 255);
    float size = 1.0;
    float id = 0;
    String description = &quot;&quot;;
    PointLine[] lines = new PointLine[4];
}
 
class PointLine {
  float x1 = 0;
  float y1 = 0;
  float x2 = 0;
  float y2 = 0;
 
  PointLine(float _x1, float _y1, float _x2, float _y2)   {
    x1=_x1;
    x2=_x2;
    y1=_y1;
    y2=_y2;
  }
}
</pre></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:85b1dcb662bc419cabfca157012ad0d9">]]></description>
      <comments>http://channel9.msdn.com/Series/Sketchbooktutorial/Text-Pens-and-Multi-Touch</comments>
      <itunes:summary>See pointers and multi-touch sketches in action&amp;nbsp; Windows 8 Store applications support a robust set of Pointer types, including finger tracking, input stylus and traditional mouse events. By expanding on some basic functionality, we can leverage these new Pointer events in our Processing.JS sketch and show how to differentiate between simultaneous and differentiated inputs. We&#39;ll also introduce adding basic text to your sketches. To follow along in Visual Studio, please download the Processing Sketchbook projection. The finished sketch for this lesson can be found below: 
ArrayList pointers = new ArrayList();
int width, height;
String txtOutput;
void setup() {
    width = 500;
    height = 550;
    size(width, height);
    smooth();
    background(0);
    fill(color(255, 255, 255));
    PFont arial = loadFont(&amp;quot;arial&amp;quot;);
     textFont(arial, 14);
}
 
void draw() {
    fill(color(0, 0, 0, 20));
    noStroke();
    rect(0, 0, width, height);
    txtOutput = pointers.size() &amp;#43; &amp;quot;:&amp;quot;;
    for(int i = 0; i &amp;lt; pointers.size(); i&amp;#43;&amp;#43;){
      Pointer p = (Pointer)pointers.get(i);
      stroke(p.pColor);
      strokeWeight(p.size);
      txtOutput &amp;#43;= p.description;
      switch ( p.description) {
        case &amp;quot;mouse&amp;quot;:
        case &amp;quot;pen&amp;quot;:
          line(p.oldX, p.oldY, p.x, p.y);
          p.oldX = p.x;
          p.oldY = p.y;
          break;
        case &amp;quot;touch&amp;quot;:
          for (int currentLine = 0; currentLine &amp;lt; 4; currentLine&amp;#43;&amp;#43;) {
            PointLine pLine = p.lines[currentLine];
            line(pLine.x1, pLine.y1, pLine.x2, pLine.y2);
          }
         updateLines(p);
         break;
       }
    }
    fill(color(255,255,255,255));
    text(txtOutput, 30, 30);
}
 
void pointerDown(TouchEvent e){
    Pointer p = new Pointer();
    p.x = e.offsetX;
    p.y = e.offsetY;
    p.oldX = e.offsetX;
    p.oldY = e.offsetY;
    p.id = e.pointerId;
  </itunes:summary>
      <itunes:duration>3298</itunes:duration>
      <link>http://channel9.msdn.com/Series/Sketchbooktutorial/Text-Pens-and-Multi-Touch</link>
      <pubDate>Mon, 22 Apr 2013 21:17:11 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Series/Sketchbooktutorial/Text-Pens-and-Multi-Touch</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/c34d/91ab7713-85fc-4923-bb83-406537fcc34d/SketchbookTutorial7_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/c34d/91ab7713-85fc-4923-bb83-406537fcc34d/SketchbookTutorial7_220.jpg" height="123" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/c34d/91ab7713-85fc-4923-bb83-406537fcc34d/SketchbookTutorial7_512.jpg" height="288" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://media.ch9.ms/ch9/c34d/91ab7713-85fc-4923-bb83-406537fcc34d/SketchbookTutorial7.mp3" expression="full" duration="3298" fileSize="52772341" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/c34d/91ab7713-85fc-4923-bb83-406537fcc34d/SketchbookTutorial7.mp4" expression="full" duration="3298" fileSize="320721563" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/c34d/91ab7713-85fc-4923-bb83-406537fcc34d/SketchbookTutorial7.webm" expression="full" duration="3298" fileSize="106333237" type="video/webm" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/c34d/91ab7713-85fc-4923-bb83-406537fcc34d/SketchbookTutorial7.wma" expression="full" duration="3298" fileSize="26674543" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/c34d/91ab7713-85fc-4923-bb83-406537fcc34d/SketchbookTutorial7.wmv" expression="full" duration="3298" fileSize="153441059" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/c34d/91ab7713-85fc-4923-bb83-406537fcc34d/SketchbookTutorial7_high.mp4" expression="full" duration="3298" fileSize="702617226" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/c34d/91ab7713-85fc-4923-bb83-406537fcc34d/SketchbookTutorial7_mid.mp4" expression="full" duration="3298" fileSize="490751847" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/c34d/91ab7713-85fc-4923-bb83-406537fcc34d/SketchbookTutorial7_Source.wmv" expression="full" duration="3298" fileSize="338160045" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/c34d/91ab7713-85fc-4923-bb83-406537fcc34d/SketchbookTutorial7.ism/manifest" expression="full" duration="3298" fileSize="6106" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://media.ch9.ms/ch9/c34d/91ab7713-85fc-4923-bb83-406537fcc34d/SketchbookTutorial7.wmv" length="153441059" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Rick Barraza</dc:creator>
      <itunes:author>Rick Barraza</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Series/Sketchbooktutorial/Text-Pens-and-Multi-Touch/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Grids, Direction and Rotation</title>
      <description><![CDATA[<p><a href="http://media.ch9.ms/coding4fun/processingjs/direction-rotation.html">See direction and rotation sketch in action</a></p><p>In this lesson, we build on the introduction to Trigonometry we explored previously and add the final piece of the puzzle,&nbsp;working with tangents using the ATAN2() function.&nbsp; This special function allows us to figure out the direction of rotation between any two elements and we use it to build a fish eye bulging effect that reacts to the pointer as it moves across the canvas.</p><p>To follow along in Visual Studio, please <a href="https://processingjs.codeplex.com/releases/view/106003">download the Processing Sketchbook projection.</a></p><p>The finished sketch for this lesson can be found below:</p><p><pre class="brush: js">
int rows = 12;
int cols = 12;
int margin = 10;
int rowsSpace;
int colsSpace;
int totalBlocks = 144;
Block[] blocks = new Block[totalBlocks];
int width, height;
float targetX, targetY;
float pointerX, pointerY;
float sketchDiagonal;
 
void setup() {
  width = 500;
  height = 550;
  size(width, height);
  rowsSpace = ( width - margin ) / rows;
  colsSpace = ( height - margin) / cols;
  sketchDiagonal = width*width &#43; height*height;
  sketchDiagonal *= .6;
  noStroke();
  smooth();
  targetX = width / 2;
  targetY = height / 2;
  pointerX = targetX;
  pointerY = targetY;
  int r = 255;
  int g = 0;
  int b = 255;
  int count = 0;
  for ( int x = 0; x &lt; rows; x&#43;&#43;) {
    for ( int y = 0; y &lt; cols; y&#43;&#43; ) {
      Block block = new Block();
      block.x = margin &#43; x*rowsSpace;
      block.y = margin &#43; y*colsSpace;
      r = map(x, 0, rows, 0, 255);
      b = map(y, 0, cols, 0, 255);
      block.baseColor = color( r, g, b, 255);
      block.rotation = 0;
      blocks[count&#43;&#43;] = block;
    }
  }
};
 
void draw() {
  background(0);
  pointerX &#43;= ( targetX - pointerX)*.16;
  pointerY &#43;= ( targetY - pointerY)*.16;
  for ( int i = 0; i &lt; totalBlocks; i&#43;&#43;) {
    float dx = blocks[i].x - pointerX;
    float dy = blocks[i].y - pointerY;
    float width = 1.0 - (dx*dx &#43; dy*dy)/sketchDiagonal;
    float angle = Math.atan2(dy, dx);
    blocks[i].wide = width*colsSpace;
    blocks[i].rotation = angle; 
    blocks[i].render();
  }
};
 
void pointerMove(TouchEvent e){
  targetX = e.offsetX;
  targetY = e.offsetY;
};
 
class Block {
  float x = 0.0;
  float y = 0.0;
  float wide = 5.0;
  float rotation = 0.0;
  color baseColor = color(255,255,255,255);
  color detailColor = color(255,255,255,255);
  void render(){
    pushMatrix();
    translate( this.x, this.y);
    fill(this.baseColor);
    rotate(this.rotation);
    rect( 0, -1, this.wide, 2);
    fill(this.detailColor);
    ellipse(0, 0, 3, 3);
    popMatrix();
  }
}
</pre></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:8507cebc27a24c1ca5f2a157012aa57d">]]></description>
      <comments>http://channel9.msdn.com/Series/Sketchbooktutorial/Grids-Direction-and-Rotation</comments>
      <itunes:summary>See direction and rotation sketch in action In this lesson, we build on the introduction to Trigonometry we explored previously and add the final piece of the puzzle,&amp;nbsp;working with tangents using the ATAN2() function.&amp;nbsp; This special function allows us to figure out the direction of rotation between any two elements and we use it to build a fish eye bulging effect that reacts to the pointer as it moves across the canvas. To follow along in Visual Studio, please download the Processing Sketchbook projection. The finished sketch for this lesson can be found below: 
int rows = 12;
int cols = 12;
int margin = 10;
int rowsSpace;
int colsSpace;
int totalBlocks = 144;
Block[] blocks = new Block[totalBlocks];
int width, height;
float targetX, targetY;
float pointerX, pointerY;
float sketchDiagonal;
 
void setup() {
  width = 500;
  height = 550;
  size(width, height);
  rowsSpace = ( width - margin ) / rows;
  colsSpace = ( height - margin) / cols;
  sketchDiagonal = width*width &amp;#43; height*height;
  sketchDiagonal *= .6;
  noStroke();
  smooth();
  targetX = width / 2;
  targetY = height / 2;
  pointerX = targetX;
  pointerY = targetY;
  int r = 255;
  int g = 0;
  int b = 255;
  int count = 0;
  for ( int x = 0; x &amp;lt; rows; x&amp;#43;&amp;#43;) {
    for ( int y = 0; y &amp;lt; cols; y&amp;#43;&amp;#43; ) {
      Block block = new Block();
      block.x = margin &amp;#43; x*rowsSpace;
      block.y = margin &amp;#43; y*colsSpace;
      r = map(x, 0, rows, 0, 255);
      b = map(y, 0, cols, 0, 255);
      block.baseColor = color( r, g, b, 255);
      block.rotation = 0;
      blocks[count&amp;#43;&amp;#43;] = block;
    }
  }
};
 
void draw() {
  background(0);
  pointerX &amp;#43;= ( targetX - pointerX)*.16;
  pointerY &amp;#43;= ( targetY - pointerY)*.16;
  for ( int i = 0; i &amp;lt; totalBlocks; i&amp;#43;&amp;#43;) {
    float dx = blocks[i].x - pointerX;
    float dy = blocks[i].y - pointerY;
    float width = 1.0 - (dx*dx &amp;#43; dy*dy)/sketchDiagonal;
    float</itunes:summary>
      <itunes:duration>2108</itunes:duration>
      <link>http://channel9.msdn.com/Series/Sketchbooktutorial/Grids-Direction-and-Rotation</link>
      <pubDate>Mon, 22 Apr 2013 21:17:04 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Series/Sketchbooktutorial/Grids-Direction-and-Rotation</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/ea87/805f2f26-45a4-403b-8519-b0063c47ea87/SketchbookTutorial6_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/ea87/805f2f26-45a4-403b-8519-b0063c47ea87/SketchbookTutorial6_220.jpg" height="123" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/ea87/805f2f26-45a4-403b-8519-b0063c47ea87/SketchbookTutorial6_512.jpg" height="288" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://media.ch9.ms/ch9/ea87/805f2f26-45a4-403b-8519-b0063c47ea87/SketchbookTutorial6.mp3" expression="full" duration="2108" fileSize="33742241" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/ea87/805f2f26-45a4-403b-8519-b0063c47ea87/SketchbookTutorial6.mp4" expression="full" duration="2108" fileSize="202921792" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/ea87/805f2f26-45a4-403b-8519-b0063c47ea87/SketchbookTutorial6.webm" expression="full" duration="2108" fileSize="66623640" type="video/webm" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/ea87/805f2f26-45a4-403b-8519-b0063c47ea87/SketchbookTutorial6.wma" expression="full" duration="2108" fileSize="17058739" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/ea87/805f2f26-45a4-403b-8519-b0063c47ea87/SketchbookTutorial6.wmv" expression="full" duration="2108" fileSize="83682053" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/ea87/805f2f26-45a4-403b-8519-b0063c47ea87/SketchbookTutorial6_high.mp4" expression="full" duration="2108" fileSize="443124674" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/ea87/805f2f26-45a4-403b-8519-b0063c47ea87/SketchbookTutorial6_mid.mp4" expression="full" duration="2108" fileSize="309638251" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/ea87/805f2f26-45a4-403b-8519-b0063c47ea87/SketchbookTutorial6_Source.wmv" expression="full" duration="2108" fileSize="166651584" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/ea87/805f2f26-45a4-403b-8519-b0063c47ea87/SketchbookTutorial6.ism/manifest" expression="full" duration="2108" fileSize="6106" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://media.ch9.ms/ch9/ea87/805f2f26-45a4-403b-8519-b0063c47ea87/SketchbookTutorial6.wmv" length="83682053" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Rick Barraza</dc:creator>
      <itunes:author>Rick Barraza</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Series/Sketchbooktutorial/Grids-Direction-and-Rotation/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Trigonometry for Designers (Don&#39;t Panic!)</title>
      <description><![CDATA[<p><a href="http://media.ch9.ms/coding4fun/processingjs/trig.html">See trig sketch in action</a></p><p>Trigonometry is the secret weapon of many top creative coders. Unfortunately for many designers, though, it was never taught in a visual or interactive way. We try and fix that with this whirlwind tour of the key concepts of SIN and COS and how we can use them to generate circles, spirals and patterns. We also introduce more advanced rendering concepts by introducing&nbsp;pushMatrix() and popMatrix() for handling rotation and scale of our visual elements. We finish off the lesson with an sketch that explores the Golden Ratio.</p><p>To follow along in Visual Studio, please <a href="https://processingjs.codeplex.com/releases/view/106003">download the Processing Sketchbook projection.</a></p><p>The finished sketch for this lesson can be found below:</p><p><pre class="brush: js">
float ToRadians = PI / 180.0;
float gAngle = 137.5077640844293;
float rotation = 0.0;
float initialRotation = 0.0;
int width, height;
int totalPetals = 300;
Petal[] petals = new Petal[totalPetals];
float radiusGrowth = 1.0049;
float radius = 60;
 
void setup() {
    width = 500;
    height = 550;
    size(width, height);
    noStroke();
    smooth();
    background(0);
    for (int i = 0; i &lt; totalPetals; i&#43;&#43;) {
        rotation &#43;= gAngle;
        radius *= radiusGrowth;
        Petal petal = new Petal();
        petal.x = width / 2 &#43; cos(rotation * ToRadians) * radius;
        petal.y = height / 2 &#43; sin(rotation * ToRadians) * radius;
        petal.rotation = rotation * ToRadians;
        petal.scale &#43;= (i * 2) / totalPetals;
        petal.render();
        petals[i] = petal;
    }
};
 
class Petal {
  float x = 0.0;
  float y = 0.0;
  float rotation = 0.0;
  float scaleVar = 1;
  color baseColor = color(0, 255, 255, 150);   
  color detailColor = color(255, 255, 255, 160);
  color trimColor = color(0, 0, 0);
  void render (){
      pushMatrix();
      translate(this.x, this.y);
      fill(this.baseColor);
      rotate(this.rotation);
      scale(this.scaleVar, this.scaleVar);
      rect(-10, -1, 20, 2);
      ellipse(0, 0, 10, 10);
      fill(this.detailColor);
      ellipse(0, 0, 8, 8);
      fill(this.trimColor);
      ellipse(0, 0, 5, 5);
      popMatrix();
  }
}
</pre></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:04ca89aa95ec450b9ff2a157012a722f">]]></description>
      <comments>http://channel9.msdn.com/Series/Sketchbooktutorial/Trigonometry-for-Designers-Dont-Panic</comments>
      <itunes:summary>See trig sketch in action Trigonometry is the secret weapon of many top creative coders. Unfortunately for many designers, though, it was never taught in a visual or interactive way. We try and fix that with this whirlwind tour of the key concepts of SIN and COS and how we can use them to generate circles, spirals and patterns. We also introduce more advanced rendering concepts by introducing&amp;nbsp;pushMatrix() and popMatrix() for handling rotation and scale of our visual elements. We finish off the lesson with an sketch that explores the Golden Ratio. To follow along in Visual Studio, please download the Processing Sketchbook projection. The finished sketch for this lesson can be found below: 
float ToRadians = PI / 180.0;
float gAngle = 137.5077640844293;
float rotation = 0.0;
float initialRotation = 0.0;
int width, height;
int totalPetals = 300;
Petal[] petals = new Petal[totalPetals];
float radiusGrowth = 1.0049;
float radius = 60;
 
void setup() {
    width = 500;
    height = 550;
    size(width, height);
    noStroke();
    smooth();
    background(0);
    for (int i = 0; i &amp;lt; totalPetals; i&amp;#43;&amp;#43;) {
        rotation &amp;#43;= gAngle;
        radius *= radiusGrowth;
        Petal petal = new Petal();
        petal.x = width / 2 &amp;#43; cos(rotation * ToRadians) * radius;
        petal.y = height / 2 &amp;#43; sin(rotation * ToRadians) * radius;
        petal.rotation = rotation * ToRadians;
        petal.scale &amp;#43;= (i * 2) / totalPetals;
        petal.render();
        petals[i] = petal;
    }
};
 
class Petal {
  float x = 0.0;
  float y = 0.0;
  float rotation = 0.0;
  float scaleVar = 1;
  color baseColor = color(0, 255, 255, 150);   
  color detailColor = color(255, 255, 255, 160);
  color trimColor = color(0, 0, 0);
  void render (){
      pushMatrix();
      translate(this.x, this.y);
      fill(this.baseColor);
      rotate(this.rotation);
      scale(this.scaleVar, this.scaleVar);
      rect(-10, -1, 20, 2);</itunes:summary>
      <itunes:duration>3041</itunes:duration>
      <link>http://channel9.msdn.com/Series/Sketchbooktutorial/Trigonometry-for-Designers-Dont-Panic</link>
      <pubDate>Mon, 22 Apr 2013 21:16:10 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Series/Sketchbooktutorial/Trigonometry-for-Designers-Dont-Panic</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/54f5/2b0dec35-cb82-452e-9f16-e5c0c00554f5/SketchbookTutorial5_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/54f5/2b0dec35-cb82-452e-9f16-e5c0c00554f5/SketchbookTutorial5_220.jpg" height="123" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/54f5/2b0dec35-cb82-452e-9f16-e5c0c00554f5/SketchbookTutorial5_512.jpg" height="288" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://media.ch9.ms/ch9/54f5/2b0dec35-cb82-452e-9f16-e5c0c00554f5/SketchbookTutorial5.mp3" expression="full" duration="3041" fileSize="48665474" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/54f5/2b0dec35-cb82-452e-9f16-e5c0c00554f5/SketchbookTutorial5.mp4" expression="full" duration="3041" fileSize="273612039" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/54f5/2b0dec35-cb82-452e-9f16-e5c0c00554f5/SketchbookTutorial5.webm" expression="full" duration="3041" fileSize="93664326" type="video/webm" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/54f5/2b0dec35-cb82-452e-9f16-e5c0c00554f5/SketchbookTutorial5.wma" expression="full" duration="3041" fileSize="24598779" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/54f5/2b0dec35-cb82-452e-9f16-e5c0c00554f5/SketchbookTutorial5.wmv" expression="full" duration="3041" fileSize="169616555" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/54f5/2b0dec35-cb82-452e-9f16-e5c0c00554f5/SketchbookTutorial5_high.mp4" expression="full" duration="3041" fileSize="626361747" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/54f5/2b0dec35-cb82-452e-9f16-e5c0c00554f5/SketchbookTutorial5_mid.mp4" expression="full" duration="3041" fileSize="435613785" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/54f5/2b0dec35-cb82-452e-9f16-e5c0c00554f5/SketchbookTutorial5_Source.wmv" expression="full" duration="3041" fileSize="363073259" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/54f5/2b0dec35-cb82-452e-9f16-e5c0c00554f5/SketchbookTutorial5.ism/manifest" expression="full" duration="3041" fileSize="6106" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://media.ch9.ms/ch9/54f5/2b0dec35-cb82-452e-9f16-e5c0c00554f5/SketchbookTutorial5.wmv" length="169616555" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Rick Barraza</dc:creator>
      <itunes:author>Rick Barraza</itunes:author>
      <slash:comments>8</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Series/Sketchbooktutorial/Trigonometry-for-Designers-Dont-Panic/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Drawing with Emitters </title>
      <description><![CDATA[<p><a href="http://media.ch9.ms/coding4fun/processingjs/emitters.html">See emitters sketch in action</a>&nbsp;</p><p>We build upon the principles learned so far and create an interactive particle emitter you can use to draw on the stage. We also look at reusing a fixed collection of elements and dynamically&nbsp;managing their life cycle.&nbsp;</p><p>To follow along in Visual Studio, please <a href="https://processingjs.codeplex.com/releases/view/106003">download the Processing Sketchbook projection.</a></p><p>The finished sketch for this lesson can be found below:</p><p><pre class="brush: js">
int totalParticles = 100;
Particle[] particles = new Particle[totalParticles];
float targetX = 0.0;
float targetY = 0.0;
int particleIndex = 0;
int width, height;
 
void setup() {
    width = 500;
    height = 550;
    size(width, height);
    noStroke();
    smooth();
    background(0);
    for (int i = 0; i &lt; totalParticles; i&#43;&#43;) {
        Particle particle = new Particle();
        particles[i] = particle;
    }
};
 
void draw() {
    fill(color(0, 0, 0, 20));
    rect(0, 0, width, height);
    for (int i = 0; i &lt; totalParticles; i&#43;&#43;) {
        particles[i].update();
        particles[i].render();
    }
};
 
void pointerMove(Pointer e) {
    targetX &#43;= (e.offsetX - targetX) * .2;
    targetY &#43;= (e.offsetY - targetY) * .2;
    var nextParticle = particles[particleIndex];
    nextParticle.reset(targetX, targetY);
    if (&#43;&#43;particleIndex &gt;= particles.length) particleIndex = 0;
}
 
class Particle {
  float x = 0.0;
  float y = 0.0;
  float vx = 0.0;
  float vy = 0.0;
  float r = 255;
  float g = 255;
  float b = 255;
  float a = 255;
  color pColor = color(255, 255, 255, 255);
  int life = 0;
 
  void update() {
    if (this.life &gt; 0) {
        this.life--;
        if (this.life &lt; 50) {
            this.x &#43;= this.vx;
            this.y &#43;= this.vy;
            this.vx &#43;= random(4) - 2;
            this.vy &#43;= random(4) - 2;
            this.vx *= .9;
            this.vy *= .9;
            this.a = 255 * (this.life / 50.0);
        }
    }
  }
 
    void reset(float _x, float _y) {
      this.x = _x;
      this.y = _y;
      this.vx = random(4) - 2;
      this.vy = random(4) * 4 - 2;
      this.life = 150;
      this.g = map(_x, 0, width, 0, 255);
      this.b = map(_y, 0, height, 0, 255);
      this.a = 255;
  }
 
  void render(){
      fill(color(this.r, this.g, this.b, this.a));
      ellipse(this.x, this.y, 5, 5);
  }
}
 </pre></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:efa67eb750fa4c328660a1570129ee87">]]></description>
      <comments>http://channel9.msdn.com/Series/Sketchbooktutorial/Drawing-with-Emitters</comments>
      <itunes:summary>See emitters sketch in action&amp;nbsp; We build upon the principles learned so far and create an interactive particle emitter you can use to draw on the stage. We also look at reusing a fixed collection of elements and dynamically&amp;nbsp;managing their life cycle.&amp;nbsp; To follow along in Visual Studio, please download the Processing Sketchbook projection. The finished sketch for this lesson can be found below: 
int totalParticles = 100;
Particle[] particles = new Particle[totalParticles];
float targetX = 0.0;
float targetY = 0.0;
int particleIndex = 0;
int width, height;
 
void setup() {
    width = 500;
    height = 550;
    size(width, height);
    noStroke();
    smooth();
    background(0);
    for (int i = 0; i &amp;lt; totalParticles; i&amp;#43;&amp;#43;) {
        Particle particle = new Particle();
        particles[i] = particle;
    }
};
 
void draw() {
    fill(color(0, 0, 0, 20));
    rect(0, 0, width, height);
    for (int i = 0; i &amp;lt; totalParticles; i&amp;#43;&amp;#43;) {
        particles[i].update();
        particles[i].render();
    }
};
 
void pointerMove(Pointer e) {
    targetX &amp;#43;= (e.offsetX - targetX) * .2;
    targetY &amp;#43;= (e.offsetY - targetY) * .2;
    var nextParticle = particles[particleIndex];
    nextParticle.reset(targetX, targetY);
    if (&amp;#43;&amp;#43;particleIndex &amp;gt;= particles.length) particleIndex = 0;
}
 
class Particle {
  float x = 0.0;
  float y = 0.0;
  float vx = 0.0;
  float vy = 0.0;
  float r = 255;
  float g = 255;
  float b = 255;
  float a = 255;
  color pColor = color(255, 255, 255, 255);
  int life = 0;
 
  void update() {
    if (this.life &amp;gt; 0) {
        this.life--;
        if (this.life &amp;lt; 50) {
            this.x &amp;#43;= this.vx;
            this.y &amp;#43;= this.vy;
            this.vx &amp;#43;= random(4) - 2;
            this.vy &amp;#43;= random(4) - 2;
            this.vx *= .9;
            this.vy *= .9;
            this.a = 255 * (this.life / 50.0);
        }
    }
  }</itunes:summary>
      <itunes:duration>1636</itunes:duration>
      <link>http://channel9.msdn.com/Series/Sketchbooktutorial/Drawing-with-Emitters</link>
      <pubDate>Mon, 22 Apr 2013 21:15:57 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Series/Sketchbooktutorial/Drawing-with-Emitters</guid>
      <media:thumbnail url="http://files.channel9.msdn.com/thumbnail/c19af535-c736-4790-8c7c-6c900e394c25.png" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://files.channel9.msdn.com/thumbnail/d48ea894-ed8c-49b4-bfbc-f3aebb50be5c.png" height="124" width="220"></media:thumbnail>
      <media:thumbnail url="http://files.channel9.msdn.com/thumbnail/499afb7f-6e6c-45a8-b848-d2322c8b1cd9.png" height="288" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://media.ch9.ms/ch9/ef38/687db814-5da8-4b8a-9339-91a17c0cef38/SketchbookTutorial4.mp3" expression="full" duration="1636" fileSize="26181778" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/ef38/687db814-5da8-4b8a-9339-91a17c0cef38/SketchbookTutorial4.mp4" expression="full" duration="1636" fileSize="156256634" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/ef38/687db814-5da8-4b8a-9339-91a17c0cef38/SketchbookTutorial4.webm" expression="full" duration="1636" fileSize="52450267" type="video/webm" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/ef38/687db814-5da8-4b8a-9339-91a17c0cef38/SketchbookTutorial4.wma" expression="full" duration="1636" fileSize="13237651" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/ef38/687db814-5da8-4b8a-9339-91a17c0cef38/SketchbookTutorial4.wmv" expression="full" duration="1636" fileSize="66563957" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/ef38/687db814-5da8-4b8a-9339-91a17c0cef38/SketchbookTutorial4_high.mp4" expression="full" duration="1636" fileSize="341964183" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/ef38/687db814-5da8-4b8a-9339-91a17c0cef38/SketchbookTutorial4_mid.mp4" expression="full" duration="1636" fileSize="239288921" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/ef38/687db814-5da8-4b8a-9339-91a17c0cef38/SketchbookTutorial4_Source.wmv" expression="full" duration="1636" fileSize="146397710" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/ef38/687db814-5da8-4b8a-9339-91a17c0cef38/SketchbookTutorial4.ism/manifest" expression="full" duration="1636" fileSize="6106" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://media.ch9.ms/ch9/ef38/687db814-5da8-4b8a-9339-91a17c0cef38/SketchbookTutorial4.wmv" length="66563957" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Rick Barraza</dc:creator>
      <itunes:author>Rick Barraza</itunes:author>
      <slash:comments>3</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Series/Sketchbooktutorial/Drawing-with-Emitters/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Jelly Blobs, Easing and Elastic</title>
      <description><![CDATA[<p><a href="http://media.ch9.ms/coding4fun/processingjs/easing-elastic.html">See easing/elastics sketch in action&nbsp;</a></p><p>Now that we can render elements to the stage, we expand our sketches to include mouse interaction. In this sketch, we create a Jelly Blob effect by nesting multiple circles with individual elastic settings to constantly follow the mouse or pointer position on screen. We also introduce the core easing algorithm and explain how it works.</p><p>To follow along in Visual Studio, please <a href="https://processingjs.codeplex.com/releases/view/106003">download the Processing Sketchbook projection.</a></p><p>The finished sketch for this lesson can be found below:</p><p><pre class="brush: js">
int totalBlobs = 10;
Blob[] blobs = new Blob[totalBlobs];
int width, height;
color strokeColor = color(255, 0, 0);
color fillColor = color(255, 255, 255);
float targetX, targetY;
 
void setup() {
    width = 500;
    height = 550;
    targetX = width / 2;
    targetY = height / 2;
    size(width, height);
    noStroke();
    smooth();
    background(0);
    for (int i = 0; i &lt; totalBlobs; i&#43;&#43;) {
        Blob blob = new Blob();
        blob.x = random(width);
        blob.y = random(height);
        blob.easingX = .02 &#43; random(.10);
        blob.easingY = .02 &#43; random(.10);
        blob.strokeSize = 100 &#43; random(160.0);
        blob.fillSize = blob.strokeSize - 20.0;
        blobs[i] = blob;
    }
};
 
void draw() {
    background(0);
    fill(strokeColor);
    for (int i = 0; i &lt; totalBlobs; i&#43;&#43;) {
        blobs[i].springToward(targetX, targetY);
        blobs[i].renderStroke();
    }
    fill(fillColor);
    for (int i = 0; i &lt; totalBlobs; i&#43;&#43;) {
        blobs[i].renderFill();
    }
}
 
void pointerMove(TouchEvent e){
    targetX = e.offsetX;
    targetY = e.offsetY;
}
 
class Blob{
  float x = 0.0;
  float y = 0.0;
  float vx = 0.0;
  float vy = 0.0;
  float easingX = 0.0;
  float easingY = 0.0;
  float strokeSize = 180.0;
  float fillSize = 160.0;
 
  void renderStroke() {
      ellipse(this.x, this.y, this.strokeSize, this.strokeSize);
  }
 
   void renderFill() {
      ellipse(this.x, this.y, this.fillSize, this.fillSize);
  }
 
  void springToward(float _x, float _y) {
      this.vx &#43;= (_x - this.x) * this.easingX;
      this.vy &#43;= (_y - this.y) * this.easingY;
      this.vx *= .92;
      this.vy *= .90;
      this.x &#43;= this.vx;
      this.y &#43;= this.vy;
  }
}
</pre></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:aefff889184e4f609d91a1570129aa02">]]></description>
      <comments>http://channel9.msdn.com/Series/Sketchbooktutorial/Jelly-Blobs-Easing-and-Elastic</comments>
      <itunes:summary>See easing/elastics sketch in action&amp;nbsp; Now that we can render elements to the stage, we expand our sketches to include mouse interaction. In this sketch, we create a Jelly Blob effect by nesting multiple circles with individual elastic settings to constantly follow the mouse or pointer position on screen. We also introduce the core easing algorithm and explain how it works. To follow along in Visual Studio, please download the Processing Sketchbook projection. The finished sketch for this lesson can be found below: 
int totalBlobs = 10;
Blob[] blobs = new Blob[totalBlobs];
int width, height;
color strokeColor = color(255, 0, 0);
color fillColor = color(255, 255, 255);
float targetX, targetY;
 
void setup() {
    width = 500;
    height = 550;
    targetX = width / 2;
    targetY = height / 2;
    size(width, height);
    noStroke();
    smooth();
    background(0);
    for (int i = 0; i &amp;lt; totalBlobs; i&amp;#43;&amp;#43;) {
        Blob blob = new Blob();
        blob.x = random(width);
        blob.y = random(height);
        blob.easingX = .02 &amp;#43; random(.10);
        blob.easingY = .02 &amp;#43; random(.10);
        blob.strokeSize = 100 &amp;#43; random(160.0);
        blob.fillSize = blob.strokeSize - 20.0;
        blobs[i] = blob;
    }
};
 
void draw() {
    background(0);
    fill(strokeColor);
    for (int i = 0; i &amp;lt; totalBlobs; i&amp;#43;&amp;#43;) {
        blobs[i].springToward(targetX, targetY);
        blobs[i].renderStroke();
    }
    fill(fillColor);
    for (int i = 0; i &amp;lt; totalBlobs; i&amp;#43;&amp;#43;) {
        blobs[i].renderFill();
    }
}
 
void pointerMove(TouchEvent e){
    targetX = e.offsetX;
    targetY = e.offsetY;
}
 
class Blob{
  float x = 0.0;
  float y = 0.0;
  float vx = 0.0;
  float vy = 0.0;
  float easingX = 0.0;
  float easingY = 0.0;
  float strokeSize = 180.0;
  float fillSize = 160.0;
 
  void renderStroke() {
      ellipse(this.x, this.y, this.strokeSize, this.strokeSize);
  }
 
</itunes:summary>
      <itunes:duration>2147</itunes:duration>
      <link>http://channel9.msdn.com/Series/Sketchbooktutorial/Jelly-Blobs-Easing-and-Elastic</link>
      <pubDate>Mon, 22 Apr 2013 21:15:06 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Series/Sketchbooktutorial/Jelly-Blobs-Easing-and-Elastic</guid>
      <media:thumbnail url="http://files.channel9.msdn.com/thumbnail/4c1e5036-aede-4174-a78f-3548699d5442.png" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://files.channel9.msdn.com/thumbnail/5cbf45e2-4191-4b4a-aed8-de93e128b6c6.png" height="124" width="220"></media:thumbnail>
      <media:thumbnail url="http://files.channel9.msdn.com/thumbnail/5df4cd6f-b5d8-4166-931e-4e138a5a802b.png" height="288" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://media.ch9.ms/ch9/3d3a/00047d95-3112-4367-95eb-2e0ca7b73d3a/SketchbookTutorial3.mp3" expression="full" duration="2147" fileSize="34365001" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/3d3a/00047d95-3112-4367-95eb-2e0ca7b73d3a/SketchbookTutorial3.mp4" expression="full" duration="2147" fileSize="204925645" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/3d3a/00047d95-3112-4367-95eb-2e0ca7b73d3a/SketchbookTutorial3.webm" expression="full" duration="2147" fileSize="63842923" type="video/webm" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/3d3a/00047d95-3112-4367-95eb-2e0ca7b73d3a/SketchbookTutorial3.wma" expression="full" duration="2147" fileSize="17374159" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/3d3a/00047d95-3112-4367-95eb-2e0ca7b73d3a/SketchbookTutorial3.wmv" expression="full" duration="2147" fileSize="88277831" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/3d3a/00047d95-3112-4367-95eb-2e0ca7b73d3a/SketchbookTutorial3_high.mp4" expression="full" duration="2147" fileSize="446625809" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/3d3a/00047d95-3112-4367-95eb-2e0ca7b73d3a/SketchbookTutorial3_mid.mp4" expression="full" duration="2147" fileSize="311955546" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/3d3a/00047d95-3112-4367-95eb-2e0ca7b73d3a/SketchbookTutorial3_Source.wmv" expression="full" duration="2147" fileSize="174884033" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/3d3a/00047d95-3112-4367-95eb-2e0ca7b73d3a/SketchbookTutorial3.ism/manifest" expression="full" duration="2147" fileSize="6106" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://media.ch9.ms/ch9/3d3a/00047d95-3112-4367-95eb-2e0ca7b73d3a/SketchbookTutorial3.wmv" length="88277831" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Rick Barraza</dc:creator>
      <itunes:author>Rick Barraza</itunes:author>
      <slash:comments>2</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Series/Sketchbooktutorial/Jelly-Blobs-Easing-and-Elastic/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Particles, Classes and Color</title>
      <description><![CDATA[<p><a href="http://media.ch9.ms/coding4fun/processingjs/particles.html">See this sketch in action</a></p><p>We create a colorful particle field. We learn how to define a class for our Particle object and have each particle&nbsp;take care of its own properties, such as position and direction. We also explore the creation of dynamic colors and some rendering tricks to make the sketch more appealing.</p><p>To follow along in Visual Studio, please <a href="https://processingjs.codeplex.com/releases/view/106003">download the Processing Sketchbook projection.</a></p><p>The finished sketch for this lesson can be found below:</p><p><pre class="brush: js">
int totalDots = 100;
Dot[] dots = new Dot[totalDots];
int width, height;
color fillColor;
float diameter = 6.0;
 
void setup() {
    // DEFINE THE STAGE
    width = 500;
    height = 550;
    size(width, height);
    // THE SAME FILL IS USED FOR ALL DOTS
    fillColor = color(255, 0, 0);
    fill(fillColor);
    noStroke();
    // CREATE A COLLECTION OF DOTS
    for (int i = 0; i &lt; totalDots; i&#43;&#43;) {
        Dot d = new Dot();
        d.x = random(width);
        d.y = random(height);
        d.vx = random(2.0) - 1.0;
        d.vy = random(2.0) - 1.0;
        dots[i] = d;
    }
    background(0);
};
 
void draw() {
    fill(0, 25);
    rect(0, 0, width, height);
    float r = 255;
    float g = 255;
    float b = 255;
    for (int i = 0; i &lt; totalDots; i&#43;&#43;) {
        r = map(dots[i].x, 0, width, 0, 255);
        g = map(dots[i].y, 0, height, 0, 255);
        fill(r, g, b);
        dots[i].update();
        ellipse(dots[i].x, dots[i].y, diameter, diameter);
    }
};
 
class Dot {
    float x = 0.0;
    float y = 0.0;
    float vx = 0.0;
    float vy = 0.0;
    void update(){
      // update the velocity
      this.vx &#43;= random(2.0) - 1.0;
      this.vx *= .96;
      this.vy &#43;= random(2.0) - 1.0;
      this.vy *= .96;
      // update the position
      this.x &#43;= this.vx;
      this.y &#43;= this.vy;
      // handle boundary collision
      if (this.x &gt; width) { this.x = width; this.vx *= -1.0; }
      if (this.x &lt; 0) { this.x = 0; this.vx *= -1.0; }
      if (this.y &gt; height) { this.y = height; this.vy *= -1.0; }
      if (this.y &lt; 0) { this.y = 0; this.vy *= -1.0; }
    }
}
</pre></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:3ce40584733348dfae10a15701296031">]]></description>
      <comments>http://channel9.msdn.com/Series/Sketchbooktutorial/Particles-Classes-and-Color</comments>
      <itunes:summary>See this sketch in action We create a colorful particle field. We learn how to define a class for our Particle object and have each particle&amp;nbsp;take care of its own properties, such as position and direction. We also explore the creation of dynamic colors and some rendering tricks to make the sketch more appealing. To follow along in Visual Studio, please download the Processing Sketchbook projection. The finished sketch for this lesson can be found below: 
int totalDots = 100;
Dot[] dots = new Dot[totalDots];
int width, height;
color fillColor;
float diameter = 6.0;
 
void setup() {
    // DEFINE THE STAGE
    width = 500;
    height = 550;
    size(width, height);
    // THE SAME FILL IS USED FOR ALL DOTS
    fillColor = color(255, 0, 0);
    fill(fillColor);
    noStroke();
    // CREATE A COLLECTION OF DOTS
    for (int i = 0; i &amp;lt; totalDots; i&amp;#43;&amp;#43;) {
        Dot d = new Dot();
        d.x = random(width);
        d.y = random(height);
        d.vx = random(2.0) - 1.0;
        d.vy = random(2.0) - 1.0;
        dots[i] = d;
    }
    background(0);
};
 
void draw() {
    fill(0, 25);
    rect(0, 0, width, height);
    float r = 255;
    float g = 255;
    float b = 255;
    for (int i = 0; i &amp;lt; totalDots; i&amp;#43;&amp;#43;) {
        r = map(dots[i].x, 0, width, 0, 255);
        g = map(dots[i].y, 0, height, 0, 255);
        fill(r, g, b);
        dots[i].update();
        ellipse(dots[i].x, dots[i].y, diameter, diameter);
    }
};
 
class Dot {
    float x = 0.0;
    float y = 0.0;
    float vx = 0.0;
    float vy = 0.0;
    void update(){
      // update the velocity
      this.vx &amp;#43;= random(2.0) - 1.0;
      this.vx *= .96;
      this.vy &amp;#43;= random(2.0) - 1.0;
      this.vy *= .96;
      // update the position
      this.x &amp;#43;= this.vx;
      this.y &amp;#43;= this.vy;
      // handle boundary collision
      if (this.x &amp;gt; width) { this.x = width; this.vx *= -1.0; }
      if (this.x &amp;lt; 0)</itunes:summary>
      <itunes:duration>2359</itunes:duration>
      <link>http://channel9.msdn.com/Series/Sketchbooktutorial/Particles-Classes-and-Color</link>
      <pubDate>Mon, 22 Apr 2013 21:14:36 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Series/Sketchbooktutorial/Particles-Classes-and-Color</guid>
      <media:thumbnail url="http://files.channel9.msdn.com/thumbnail/11e2788a-4a43-47a0-98b8-bfc9a52629df.png" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://files.channel9.msdn.com/thumbnail/5fa83942-e95e-4f79-aaec-75a6278c9782.png" height="124" width="220"></media:thumbnail>
      <media:thumbnail url="http://files.channel9.msdn.com/thumbnail/01cd1661-abbb-4d42-96af-27001cc16a57.png" height="288" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://media.ch9.ms/ch9/a8ad/309c4dd4-aebf-426f-a868-bd74ea83a8ad/SketchbookTutorial2.mp3" expression="full" duration="2359" fileSize="37750470" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/a8ad/309c4dd4-aebf-426f-a868-bd74ea83a8ad/SketchbookTutorial2.mp4" expression="full" duration="2359" fileSize="230562725" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/a8ad/309c4dd4-aebf-426f-a868-bd74ea83a8ad/SketchbookTutorial2.webm" expression="full" duration="2359" fileSize="73373652" type="video/webm" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/a8ad/309c4dd4-aebf-426f-a868-bd74ea83a8ad/SketchbookTutorial2.wma" expression="full" duration="2359" fileSize="19083435" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/a8ad/309c4dd4-aebf-426f-a868-bd74ea83a8ad/SketchbookTutorial2.wmv" expression="full" duration="2359" fileSize="119085383" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/a8ad/309c4dd4-aebf-426f-a868-bd74ea83a8ad/SketchbookTutorial2_high.mp4" expression="full" duration="2359" fileSize="505884870" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/a8ad/309c4dd4-aebf-426f-a868-bd74ea83a8ad/SketchbookTutorial2_mid.mp4" expression="full" duration="2359" fileSize="355545071" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/a8ad/309c4dd4-aebf-426f-a868-bd74ea83a8ad/SketchbookTutorial2_Source.wmv" expression="full" duration="2359" fileSize="226967690" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/a8ad/309c4dd4-aebf-426f-a868-bd74ea83a8ad/SketchbookTutorial2.ism/manifest" expression="full" duration="2359" fileSize="6106" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://media.ch9.ms/ch9/a8ad/309c4dd4-aebf-426f-a868-bd74ea83a8ad/SketchbookTutorial2.wmv" length="119085383" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Rick Barraza</dc:creator>
      <itunes:author>Rick Barraza</itunes:author>
      <slash:comments>3</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Series/Sketchbooktutorial/Particles-Classes-and-Color/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Setting up your Windows 8 environment</title>
      <description><![CDATA[<p>We look at how a Windows 8 store application built in JavaScript can take advantage of the Processing.JS library for creative coding. We also provide an overview of what a basic Processing.JS sketch looks like while setting up the draw() and update() functions for our first sketch.</p><p>To follow along in Visual Studio, please <a href="https://processingjs.codeplex.com/releases/view/106003">download the Processing Sketchbook projection.</a></p><p>The finished sketch can be found below:</p><p><pre class="brush: js">
int width;
int height;
int diameter = 100;
color fillColor;
float x, y, vx, vy;
 
void setup() {    
     // setup is called once at start up.    
     width = 500;
     height = 550;
     size(width, height);    
     x = width / 2;    
     y = height / 2;    
     vx = random(20.0) - 10.0;    
     vy = random(20.0) - 10.0;    
     fillColor = color(255, 0, 0);    
     fill(fillColor);
};
 
void draw(){    
     // draw is called repeatedly    
     // clear out the background    
     background(0);    
     // draw the circle at the correct position    
     ellipse(x, y, diameter, diameter);    
     // add velocity to the position    
     x &#43;= vx;
     y &#43;= vy;    
     // bounce off the walls    
     if (x &gt; width) {
          x = width;
          vx *= -1.0;
     }    
     if (x &lt; 0) {
          x = 0;
          vx *= -1.0;
     }    
     if (y &gt; height) {
          y = height;         
          vy *= -1.0;
     }    
     if (y &lt; 0) {
          y = 0;
          vy *= -1.0;
     }
};
</pre></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:518bf7b4fdf9409ba906a1560171d65e">]]></description>
      <comments>http://channel9.msdn.com/Series/Sketchbooktutorial/Setting-up-your-Windows-8-environment</comments>
      <itunes:summary>We look at how a Windows 8 store application built in JavaScript can take advantage of the Processing.JS library for creative coding. We also provide an overview of what a basic Processing.JS sketch looks like while setting up the draw() and update() functions for our first sketch. To follow along in Visual Studio, please download the Processing Sketchbook projection. The finished sketch can be found below: 
int width;
int height;
int diameter = 100;
color fillColor;
float x, y, vx, vy;
 
void setup() {    
     // setup is called once at start up.    
     width = 500;
     height = 550;
     size(width, height);    
     x = width / 2;    
     y = height / 2;    
     vx = random(20.0) - 10.0;    
     vy = random(20.0) - 10.0;    
     fillColor = color(255, 0, 0);    
     fill(fillColor);
};
 
void draw(){    
     // draw is called repeatedly    
     // clear out the background    
     background(0);    
     // draw the circle at the correct position    
     ellipse(x, y, diameter, diameter);    
     // add velocity to the position    
     x &amp;#43;= vx;
     y &amp;#43;= vy;    
     // bounce off the walls    
     if (x &amp;gt; width) {
          x = width;
          vx *= -1.0;
     }    
     if (x &amp;lt; 0) {
          x = 0;
          vx *= -1.0;
     }    
     if (y &amp;gt; height) {
          y = height;         
          vy *= -1.0;
     }    
     if (y &amp;lt; 0) {
          y = 0;
          vy *= -1.0;
     }
};
 </itunes:summary>
      <itunes:duration>1308</itunes:duration>
      <link>http://channel9.msdn.com/Series/Sketchbooktutorial/Setting-up-your-Windows-8-environment</link>
      <pubDate>Mon, 22 Apr 2013 21:13:54 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Series/Sketchbooktutorial/Setting-up-your-Windows-8-environment</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/65a5/e5133d9d-0105-4817-aaea-86f0089165a5/SketchbookTutorial1_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/65a5/e5133d9d-0105-4817-aaea-86f0089165a5/SketchbookTutorial1_220.jpg" height="123" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/65a5/e5133d9d-0105-4817-aaea-86f0089165a5/SketchbookTutorial1_512.jpg" height="288" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://media.ch9.ms/ch9/65a5/e5133d9d-0105-4817-aaea-86f0089165a5/SketchbookTutorial1.mp3" expression="full" duration="1308" fileSize="20934718" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/65a5/e5133d9d-0105-4817-aaea-86f0089165a5/SketchbookTutorial1.mp4" expression="full" duration="1308" fileSize="123300921" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/65a5/e5133d9d-0105-4817-aaea-86f0089165a5/SketchbookTutorial1.webm" expression="full" duration="1308" fileSize="38863907" type="video/webm" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/65a5/e5133d9d-0105-4817-aaea-86f0089165a5/SketchbookTutorial1.wma" expression="full" duration="1308" fileSize="10585119" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/65a5/e5133d9d-0105-4817-aaea-86f0089165a5/SketchbookTutorial1.wmv" expression="full" duration="1308" fileSize="51651869" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/65a5/e5133d9d-0105-4817-aaea-86f0089165a5/SketchbookTutorial1_high.mp4" expression="full" duration="1308" fileSize="269751850" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/65a5/e5133d9d-0105-4817-aaea-86f0089165a5/SketchbookTutorial1_mid.mp4" expression="full" duration="1308" fileSize="188403870" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/65a5/e5133d9d-0105-4817-aaea-86f0089165a5/SketchbookTutorial1_Source.wmv" expression="full" duration="1308" fileSize="104760198" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/65a5/e5133d9d-0105-4817-aaea-86f0089165a5/SketchbookTutorial1.ism/manifest" expression="full" duration="1308" fileSize="6106" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://media.ch9.ms/ch9/65a5/e5133d9d-0105-4817-aaea-86f0089165a5/SketchbookTutorial1.wmv" length="51651869" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Rick Barraza</dc:creator>
      <itunes:author>Rick Barraza</itunes:author>
      <slash:comments>4</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Series/Sketchbooktutorial/Setting-up-your-Windows-8-environment/RSS</wfw:commentRss>
    </item>
  <item>
      <title>TWC9: Azure Active Directory, Unity, Philips Hue and a little GunPowder</title>
      <description><![CDATA[<p>This week on Channel 9, Dan and Rick discuss the week's top developer news, including;</p><ul><li><a href="http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-April-12-2013#time=0m36s">[00:36]</a> <a href="http://weblogs.asp.net/scottgu/archive/2013/04/08/windows-azure-active-directory-general-availability-new-backup-service-web-site-monitoring-and-diagnostic-improvements.aspx">Windows Azure: Active Directory Release, New Backup Service &#43; Web Site Monitoring and Log Improvements</a> (Scott Guthrie) </li><li><a href="http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-April-12-2013#time=2m13s">[02:13]</a> <a href="http://www.cloudidentity.com/blog/2013/04/08/walkthrough-1-adding-sign-on-to-your-web-application-using-windows-azure-ad/">Walkthrough #1: Adding Sign-On to Your Web Application Using Windows Azure AD</a> (Vittorio Bertocci) </li><li><a href="http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-April-12-2013#time=3m28s">[03:28]</a> <a href="http://digitalerr0r.wordpress.com/2013/04/04/html5-game-starterkit-for-windows-8-with-leaderboard-in-windows-azure/">Game Starterkit for Windows 8 with leaderboard in Windows Azure</a> (Petri Wilhelmsen) </li><li><a href="http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-April-12-2013#time=4m53s">[04:53]</a> <a href="http://channel9.msdn.com/Events/Windows-Camp/Building-Windows-Games-with-Unity">Channel 9 Highlight: Building Windows Games with Unity</a> </li><li><a href="http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-April-12-2013#time=8m06s">[08:06]</a> <a href="http://forum.unity3d.com/threads/26785-Unity-Jump-Start-Video-Tutorials" target="_blank">Unity for Beginners Tutorial</a> </li><li><a href="http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-April-12-2013#time=11m30s">[11:30]</a> <a href="http://www.dotnetkicks.com/stories/49286/complete-guide-to-dynamic-keyword-in-c-sharp">Complete guide to dynamic keyword in C#</a> (Punit Ganshani) [Found Via: <a href="http://www.dotnetkicks.com/stories/49286/complete-guide-to-dynamic-keyword-in-c-sharp">Complete guide to Dynamic keyword in C#</a>] </li><li><a href="http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-April-12-2013#time=12m45s">[12:45]</a> <a href="http://channel9.msdn.com/coding4fun/articles/Philips-Hue-Lighting-Controller">Philips Hue Lighting Controller</a> (Clint Rutkas, Jarem Archer) </li><li><a href="http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-April-12-2013#time=13m58s">[13:58]</a> <a href="http://thecurlybrace.blogspot.com/2013/04/how-to-create-database-first-code-first.html">How to Create a Database-First Code-First Entity Framework 5 Model</a> (Mike Christian) </li><li><a href="http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-April-12-2013#time=15m08s">[15:08]</a> <a href="http://www.diaryofaninja.com/blog/2013/04/10/make-testing-the-untestable-easy-with-visual-studio-2012-update-2-and-the-microsoft-fakes-framework">Make Testing the Untestable Easy with Visual Studio 2012 Update 2 and the Microsoft Fakes Framework</a> (Doug Rathbone) </li><li><a href="http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-April-12-2013#time=15m50s">[15:50]</a> <a href="http://www.brentozar.com/archive/2013/04/free-sql-server-training-videos-for-developers/">Free SQL Server Training Videos for Developers</a> (Brent Ozar) </li></ul><p><strong>Picks of the Week!</strong></p><ul><li>Dan's Pick of the Week:<a href="http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-April-12-2013#time=17m46s">[17:46]</a> <a href="http://blog.roguerocketgames.com/2013/02/gunpowder-now-out-for-windows-8-and.html" target="_blank">GunPowder - Rogue Rocket Games</a> </li><li>Rick's Pick of the Week:<a href="http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-April-12-2013#time=19m20s">[19:20]</a> <a href="http://www.i-programmer.info/projects/119-graphics-and-games/5735-how-to-draw-einsteins-face-parametrically.html">How To Draw Einstein's Face Parametrically</a> (Mike James) </li></ul> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:eb39536deb05428b8d6da19d0171bf31">]]></description>
      <comments>http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-April-12-2013</comments>
      <itunes:summary>This week on Channel 9, Dan and Rick discuss the week&#39;s top developer news, including; [00:36] Windows Azure: Active Directory Release, New Backup Service &amp;#43; Web Site Monitoring and Log Improvements (Scott Guthrie) [02:13] Walkthrough #1: Adding Sign-On to Your Web Application Using Windows Azure AD (Vittorio Bertocci) [03:28] Game Starterkit for Windows 8 with leaderboard in Windows Azure (Petri Wilhelmsen) [04:53] Channel 9 Highlight: Building Windows Games with Unity [08:06] Unity for Beginners Tutorial [11:30] Complete guide to dynamic keyword in C# (Punit Ganshani) [Found Via: Complete guide to Dynamic keyword in C#] [12:45] Philips Hue Lighting Controller (Clint Rutkas, Jarem Archer) [13:58] How to Create a Database-First Code-First Entity Framework 5 Model (Mike Christian) [15:08] Make Testing the Untestable Easy with Visual Studio 2012 Update 2 and the Microsoft Fakes Framework (Doug Rathbone) [15:50] Free SQL Server Training Videos for Developers (Brent Ozar) Picks of the Week! Dan&#39;s Pick of the Week:[17:46] GunPowder - Rogue Rocket Games Rick&#39;s Pick of the Week:[19:20] How To Draw Einstein&#39;s Face Parametrically (Mike James) </itunes:summary>
      <itunes:duration>1274</itunes:duration>
      <link>http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-April-12-2013</link>
      <pubDate>Fri, 12 Apr 2013 22:04:33 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-April-12-2013</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/62a7/2deb93fa-7d3d-4c84-828d-367fde2a62a7/20130412TWC9_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/62a7/2deb93fa-7d3d-4c84-828d-367fde2a62a7/20130412TWC9_220.jpg" height="123" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/62a7/2deb93fa-7d3d-4c84-828d-367fde2a62a7/20130412TWC9_512.jpg" height="288" width="512"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/62a7/2deb93fa-7d3d-4c84-828d-367fde2a62a7/20130412TWC9_960.jpg" height="540" width="960"></media:thumbnail>
      <media:group>
        <media:content url="http://media.ch9.ms/ch9/62a7/2deb93fa-7d3d-4c84-828d-367fde2a62a7/20130412TWC9.mp3" expression="full" duration="1274" fileSize="20393900" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/62a7/2deb93fa-7d3d-4c84-828d-367fde2a62a7/20130412TWC9.mp4" expression="full" duration="1274" fileSize="121549367" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/62a7/2deb93fa-7d3d-4c84-828d-367fde2a62a7/20130412TWC9.webm" expression="full" duration="1274" fileSize="47093812" type="video/webm" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/62a7/2deb93fa-7d3d-4c84-828d-367fde2a62a7/20130412TWC9.wma" expression="full" duration="1274" fileSize="10311755" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/62a7/2deb93fa-7d3d-4c84-828d-367fde2a62a7/20130412TWC9.wmv" expression="full" duration="1274" fileSize="79422137" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/62a7/2deb93fa-7d3d-4c84-828d-367fde2a62a7/20130412TWC9_high.mp4" expression="full" duration="1274" fileSize="266285252" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/62a7/2deb93fa-7d3d-4c84-828d-367fde2a62a7/20130412TWC9_mid.mp4" expression="full" duration="1274" fileSize="186106806" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/62a7/2deb93fa-7d3d-4c84-828d-367fde2a62a7/20130412TWC9_Source.wmv" expression="full" duration="1274" fileSize="261341901" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/62a7/2deb93fa-7d3d-4c84-828d-367fde2a62a7/20130412TWC9.ism/manifest" expression="full" duration="1274" fileSize="6036" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://media.ch9.ms/ch9/62a7/2deb93fa-7d3d-4c84-828d-367fde2a62a7/20130412TWC9.wmv" length="79422137" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Dan Fernandez, Greg Duncan, Rick Barraza</dc:creator>
      <itunes:author>Dan Fernandez, Greg Duncan, Rick Barraza</itunes:author>
      <slash:comments>2</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-April-12-2013/RSS</wfw:commentRss>
      <category>C#</category>
      <category>Entity Framework</category>
      <category>SQL Server</category>
      <category>Unit Testing</category>
      <category>Unity</category>
      <category>Windows Azure</category>
      <category>Game Development</category>
      <category>Windows 8</category>
    </item>
  <item>
      <title>Channel 9 turns 9!</title>
      <description><![CDATA[<p><span>From our humble beginnings as a website built with alpha quality forum technologies that we stitched together with creative code and a lot of love, and our videos were made by a few dudes roaming the halls of Microsoft with a cheap camcorder – look at us now. Channel 9 streams live events to 100,000s of people around the world, we have a state of the art recording studio, we do C9 Live at events around the world bringing you directly into the conversation with Microsoft folks in real time. Today, much of our content is created from folks around the company. Channel 9 is THE place to watch MS events on demand and to learn about our technologies from the people who make them – people are the lifeblood of software and technology. Channel 9 is people! <br><br>Today marks 9 years of 9. It's a very special day. We are especially humbled and honored to still be around given the change rate of the web. We thank all past, present and future Niners for the excellent conversations, arguments, debates, entertainment, and camaraderie. &nbsp;9 Years of 9. That rolls so nicely off the tongue.&nbsp; Here's to 9 more.</span></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:5982f907684740249cfea182000a5272">]]></description>
      <comments>http://channel9.msdn.com/Blogs/C9Team/Channel-9-turns-9</comments>
      <itunes:summary>From our humble beginnings as a website built with alpha quality forum technologies that we stitched together with creative code and a lot of love, and our videos were made by a few dudes roaming the halls of Microsoft with a cheap camcorder – look at us now. Channel 9 streams live events to 100,000s of people around the world, we have a state of the art recording studio, we do C9 Live at events around the world bringing you directly into the conversation with Microsoft folks in real time. Today, much of our content is created from folks around the company. Channel 9 is THE place to watch MS events on demand and to learn about our technologies from the people who make them – people are the lifeblood of software and technology. Channel 9 is people! Today marks 9 years of 9. It&#39;s a very special day. We are especially humbled and honored to still be around given the change rate of the web. We thank all past, present and future Niners for the excellent conversations, arguments, debates, entertainment, and camaraderie. &amp;nbsp;9 Years of 9. That rolls so nicely off the tongue.&amp;nbsp; Here&#39;s to 9 more. </itunes:summary>
      <itunes:duration>562</itunes:duration>
      <link>http://channel9.msdn.com/Blogs/C9Team/Channel-9-turns-9</link>
      <pubDate>Fri, 15 Mar 2013 13:00:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Blogs/C9Team/Channel-9-turns-9</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/9826/a8204213-5530-4743-90d2-e3e3b58b9826/Channel9turns9_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/9826/a8204213-5530-4743-90d2-e3e3b58b9826/Channel9turns9_220.jpg" height="123" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/9826/a8204213-5530-4743-90d2-e3e3b58b9826/Channel9turns9_512.jpg" height="288" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://media.ch9.ms/ch9/9826/a8204213-5530-4743-90d2-e3e3b58b9826/Channel9turns9.mp3" expression="full" duration="562" fileSize="9007482" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/9826/a8204213-5530-4743-90d2-e3e3b58b9826/Channel9turns9.mp4" expression="full" duration="562" fileSize="52588716" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/9826/a8204213-5530-4743-90d2-e3e3b58b9826/Channel9turns9.webm" expression="full" duration="562" fileSize="21935504" type="video/webm" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/9826/a8204213-5530-4743-90d2-e3e3b58b9826/Channel9turns9.wma" expression="full" duration="562" fileSize="4559095" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/9826/a8204213-5530-4743-90d2-e3e3b58b9826/Channel9turns9.wmv" expression="full" duration="562" fileSize="62278697" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/9826/a8204213-5530-4743-90d2-e3e3b58b9826/Channel9turns9_high.mp4" expression="full" duration="562" fileSize="114186491" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/9826/a8204213-5530-4743-90d2-e3e3b58b9826/Channel9turns9_mid.mp4" expression="full" duration="562" fileSize="79671024" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/9826/a8204213-5530-4743-90d2-e3e3b58b9826/Channel9turns9_Source.wmv" expression="full" duration="562" fileSize="313490493" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/9826/a8204213-5530-4743-90d2-e3e3b58b9826/Channel9turns9.ism/manifest" expression="full" duration="562" fileSize="8462" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://media.ch9.ms/ch9/9826/a8204213-5530-4743-90d2-e3e3b58b9826/Channel9turns9.wmv" length="62278697" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Brian Peek, Charles, Clint Rutkas, Dan Fernandez, Duncan Mackenzie, Jeff Sandquist, Larry Larsen, Laura Foy, Golnaz, Rick Barraza</dc:creator>
      <itunes:author>Brian Peek, Charles, Clint Rutkas, Dan Fernandez, Duncan Mackenzie, Jeff Sandquist, Larry Larsen, Laura Foy, Golnaz, Rick Barraza</itunes:author>
      <slash:comments>48</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Blogs/C9Team/Channel-9-turns-9/RSS</wfw:commentRss>
    </item>
  <item>
      <title>TWC9: Five Years! TFS &amp; VS Git, VS2012.2, Blend news, Hyper-V for Dev&#39;s and more</title>
      <description><![CDATA[<p>This week on Channel 9, Brian and Rick discuss the week's top developer news, including;</p><ul><li><a href="http://channel9.msdn.com/Shows/This&#43;Week&#43;On&#43;Channel&#43;9/TWC9-February-01-2013#time=1m1s">[1:01]</a>&nbsp;<a href="http://channel9.msdn.com/posts/GitForVisualStudioTFS">Git Support Added to Visual Studio and TFS</a> (Martin Woodward, Brian Keller) </li><li><a href="http://channel9.msdn.com/Shows/This&#43;Week&#43;On&#43;Channel&#43;9/TWC9-February-01-2013#time=3m14s">[3:14]</a>&nbsp;<a href="http://blogs.msdn.com/b/visualstudioalm/archive/2013/01/30/getting-started-with-git-in-visual-studio-and-team-foundation-service.aspx">Getting Started with Git in Visual Studio and Team Foundation Service</a> (Matthew Mitrik (MS), Andy Lewis, and Martin Woodward) </li><li><a href="http://channel9.msdn.com/Shows/This&#43;Week&#43;On&#43;Channel&#43;9/TWC9-February-01-2013#time=3m39s">[3:39]</a>&nbsp;<a href="http://blogs.msdn.com/b/bharry/archive/2013/01/30/announcing-visual-studio-2012-update-2-vs2012-2.aspx">Announcing Visual Studio 2012 Update 2 (VS2012.2)</a> (Brian Harry) </li><li><a href="http://channel9.msdn.com/Shows/This&#43;Week&#43;On&#43;Channel&#43;9/TWC9-February-01-2013#time=6m35s">[6:35]</a>&nbsp;<a href="http://blendinsider.com/technical/announcing-visual-studio-2012-update-2-ctp-2013-01-30/">Announcing Visual Studio 2012 Update 2 CTP 2 (Blend fro VS 2012)</a>(Unni Ravindranathan) </li><li><a href="http://channel9.msdn.com/Shows/This&#43;Week&#43;On&#43;Channel&#43;9/TWC9-February-01-2013#time=7m51s">[7:51]</a>&nbsp;<a href="http://bloggingabout.net/blogs/dries/archive/2013/01/29/installing-your-app-on-your-windows-rt-device.aspx">Installing your app on your Windows RT device</a> (Dries Marckmann) </li><li><a href="http://channel9.msdn.com/Shows/This&#43;Week&#43;On&#43;Channel&#43;9/TWC9-February-01-2013#time=8m41s">[8:41]</a>&nbsp;<a href="http://wp.qmatteoq.com/lex-db-a-new-database-storage-solution-for-windows-phone-8/">Lex.db: a new database storage solution for Windows Phone 8</a> (Matteo Pagani ) </li><li><a href="http://channel9.msdn.com/Shows/This&#43;Week&#43;On&#43;Channel&#43;9/TWC9-February-01-2013#time=9m16s">[9:16]</a>&nbsp;<a href="http://blogs.microsoft.co.il/blogs/shair/archive/2013/01/30/winrt-toast-notification-from-desktop-application.aspx">WinRT Toast Notification From Desktop Application</a> (Shai Raiten) </li><li><a href="http://channel9.msdn.com/Shows/This&#43;Week&#43;On&#43;Channel&#43;9/TWC9-February-01-2013#time=11m29s">[11:29]</a>&nbsp;<a href="http://geekswithblogs.net/Optikal/archive/2013/01/27/151951.aspx">Managing Parallel Team Development–Using NuGet</a> (Dylan Smith) </li><li><a href="http://channel9.msdn.com/Shows/This&#43;Week&#43;On&#43;Channel&#43;9/TWC9-February-01-2013#time=12m23s">[12:23]</a>&nbsp;<a href="http://www.eweek.com/developer/microsoft-launches-modern.ie-internet-explorer-testing-resource/">Microsoft Launches modern.IE Internet Explorer Testing Resource</a> (Darryl K. Taft), <a href="http://modern.ie/">modern.IE</a> </li><li><a href="http://channel9.msdn.com/Shows/This&#43;Week&#43;On&#43;Channel&#43;9/TWC9-February-01-2013#time=13m46s">[13:46]</a>&nbsp;<a href="http://weblogs.asp.net/gunnarpeipman/archive/2013/01/28/using-visual-studio-database-projects-in-real-life.aspx">Using Visual Studio database projects in real life</a> (Gunnar Peipman) </li><li><a href="http://channel9.msdn.com/Shows/This&#43;Week&#43;On&#43;Channel&#43;9/TWC9-February-01-2013#time=15m40s">[15:40]</a>&nbsp;<a href="http://www.codeproject.com/Articles/212377/Multithreading-Demystified">Multithreading Demystified</a> (anshu dutta) </li><li><a href="http://channel9.msdn.com/Shows/This&#43;Week&#43;On&#43;Channel&#43;9/TWC9-February-01-2013#time=16m42s">[16:42]</a>&nbsp;<a href="http://blogs.msdn.com/b/zainnab/archive/2013/01/31/visual-studio-2012-color-theme-choices.aspx">Visual Studio 2012 Color Theme Choices</a> (Zain Naboulsi), <a href="http://studiostyl.es/">http://studiostyl.es/</a>, <a href="http://visualstudiogallery.msdn.microsoft.com/366ad100-0003-4c9a-81a8-337d4e7ace05">Visual Studio Color Theme Editor</a> </li><li><a href="http://channel9.msdn.com/Shows/This&#43;Week&#43;On&#43;Channel&#43;9/TWC9-February-01-2013#time=17m29s">[17:29]</a>&nbsp;<a href="http://blogs.msdn.com/b/kenkilty/archive/2013/01/30/hyperv-for-developers-part-1.aspx">Hyper-V for Developers Part 1</a> (Ken Kilty) </li></ul><p><strong>Picks of the Week!</strong></p><ul><li>Rick's Pick of the Week:<a href="http://channel9.msdn.com/Shows/This&#43;Week&#43;On&#43;Channel&#43;9/TWC9-February-01-2013#time=18m38s">[18:38]</a> <a href="http://geekswithblogs.net/mikebmcl/archive/2013/01/31/windows-store-directx-c-sample-base.aspx" target="_blank">Windows Store DirectX C&#43;&#43; Sample Base</a>, <a href="http://channel9.msdn.com/coding4fun/projects/Maelstrom" target="_blank">Maelstrom</a> </li><li>Brian's Pick of the Week:<a href="http://channel9.msdn.com/Shows/This&#43;Week&#43;On&#43;Channel&#43;9/TWC9-February-01-2013#time=20m29s">[20:29]</a> <a href="http://www.windowsphone.com/en-us/store/app/nokia-drive-beta/9a0f7585-9f16-47d5-8041-28018fcea606" target="_blank">Nokia Drive&#43; Beta for all Windows Phone 8</a> </li></ul> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:a988aba0414d4538baa3a15801533b90">]]></description>
      <comments>http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-February-01-2013</comments>
      <itunes:summary>This week on Channel 9, Brian and Rick discuss the week&#39;s top developer news, including; [1:01]&amp;nbsp;Git Support Added to Visual Studio and TFS (Martin Woodward, Brian Keller) [3:14]&amp;nbsp;Getting Started with Git in Visual Studio and Team Foundation Service (Matthew Mitrik (MS), Andy Lewis, and Martin Woodward) [3:39]&amp;nbsp;Announcing Visual Studio 2012 Update 2 (VS2012.2) (Brian Harry) [6:35]&amp;nbsp;Announcing Visual Studio 2012 Update 2 CTP 2 (Blend fro VS 2012)(Unni Ravindranathan) [7:51]&amp;nbsp;Installing your app on your Windows RT device (Dries Marckmann) [8:41]&amp;nbsp;Lex.db: a new database storage solution for Windows Phone 8 (Matteo Pagani ) [9:16]&amp;nbsp;WinRT Toast Notification From Desktop Application (Shai Raiten) [11:29]&amp;nbsp;Managing Parallel Team Development–Using NuGet (Dylan Smith) [12:23]&amp;nbsp;Microsoft Launches modern.IE Internet Explorer Testing Resource (Darryl K. Taft), modern.IE [13:46]&amp;nbsp;Using Visual Studio database projects in real life (Gunnar Peipman) [15:40]&amp;nbsp;Multithreading Demystified (anshu dutta) [16:42]&amp;nbsp;Visual Studio 2012 Color Theme Choices (Zain Naboulsi), http://studiostyl.es/, Visual Studio Color Theme Editor [17:29]&amp;nbsp;Hyper-V for Developers Part 1 (Ken Kilty) Picks of the Week! Rick&#39;s Pick of the Week:[18:38] Windows Store DirectX C&amp;#43;&amp;#43; Sample Base, Maelstrom Brian&#39;s Pick of the Week:[20:29] Nokia Drive&amp;#43; Beta for all Windows Phone 8 </itunes:summary>
      <itunes:duration>1329</itunes:duration>
      <link>http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-February-01-2013</link>
      <pubDate>Sun, 03 Feb 2013 04:08:05 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-February-01-2013</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/9ef9/0f5193e6-f340-4b68-ac2d-2309cb8f9ef9/TWC920130201_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/9ef9/0f5193e6-f340-4b68-ac2d-2309cb8f9ef9/TWC920130201_220.jpg" height="123" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/9ef9/0f5193e6-f340-4b68-ac2d-2309cb8f9ef9/TWC920130201_512.jpg" height="288" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://media.ch9.ms/ch9/9ef9/0f5193e6-f340-4b68-ac2d-2309cb8f9ef9/TWC920130201.mp3" expression="full" duration="1329" fileSize="21275793" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/9ef9/0f5193e6-f340-4b68-ac2d-2309cb8f9ef9/TWC920130201.mp4" expression="full" duration="1329" fileSize="126178038" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/9ef9/0f5193e6-f340-4b68-ac2d-2309cb8f9ef9/TWC920130201.webm" expression="full" duration="1329" fileSize="49091181" type="video/webm" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/9ef9/0f5193e6-f340-4b68-ac2d-2309cb8f9ef9/TWC920130201.wma" expression="full" duration="1329" fileSize="10759351" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://media.ch9.ms/ch9/9ef9/0f5193e6-f340-4b68-ac2d-2309cb8f9ef9/TWC920130201.wmv" expression="full" duration="1329" fileSize="94236971" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/9ef9/0f5193e6-f340-4b68-ac2d-2309cb8f9ef9/TWC920130201_high.mp4" expression="full" duration="1329" fileSize="276634607" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/9ef9/0f5193e6-f340-4b68-ac2d-2309cb8f9ef9/TWC920130201_mid.mp4" expression="full" duration="1329" fileSize="193255047" type="video/mp4" medium="video"></media:content>
        <media:content url="http://media.ch9.ms/ch9/9ef9/0f5193e6-f340-4b68-ac2d-2309cb8f9ef9/TWC920130201_Source.wmv" expression="full" duration="1329" fileSize="252168300" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/9ef9/0f5193e6-f340-4b68-ac2d-2309cb8f9ef9/TWC920130201.ism/manifest" expression="full" duration="1329" fileSize="6036" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://media.ch9.ms/ch9/9ef9/0f5193e6-f340-4b68-ac2d-2309cb8f9ef9/TWC920130201.wmv" length="94236971" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Brian Keller, Greg Duncan, Rick Barraza</dc:creator>
      <itunes:author>Brian Keller, Greg Duncan, Rick Barraza</itunes:author>
      <slash:comments>4</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-February-01-2013/RSS</wfw:commentRss>
      <category>Blend</category>
      <category>Hyper-V</category>
      <category>Team Foundation Server</category>
      <category>Visual Studio</category>
      <category>Windows Phone</category>
      <category>NuGet</category>
      <category>WinRT</category>
    </item>
  <item>
      <title>Fall Fury: Part 12 - Conclusions</title>
      <description><![CDATA[<h3>Project Conclusions</h3><p>Developing FallFury was a fun and educational activity. Besides the fact that I got to work with an amazing team of people who were willing to assist me with the testing and development, I learned some important points about the development process as a whole and have outlined them in this article.&nbsp; Check out the video for this article at <a href="http://channel9.msdn.com/Series/FallFury/Part-12-Project-Conclusion">http://channel9.msdn.com/Series/FallFury/Part-12-Project-Conclusion</a>.&nbsp; For a complete, offline version of this series, you may <a href="http://media.ch9.ms/coding4fun/fallfury/FallFury.pdf">download a nicely formatted PDF of all the articles</a>.</p><h4>Go Outside Your Comfort Zone</h4><p>This past summer, I decided to tackle a new challenge—game development. Never before had I built a game from the ground up. Moreover, as I could already find my way around C# code, I decided that I wanted to make C&#43;&#43; the language of choice, and so worked with DirectX instead of XNA. Additionally, the project needed to be constructed with Windows 8 as the target platform and I’d have to rely on the WinRT stack.</p><p>The concepts were new to me, but I figured that learning about a new platform and a new language would be more interesting than sticking to my comfort zone. Through FallFury I extended my knowledge about pointers, trigonometry, how DirectX handles a lot of the graphics legwork, and how to write HLSL shaders.</p><p>It was a challenging but very rewarding experience.</p><h4>Communicate</h4><p>The most important part of any project is communication. There are always people who know more than you in one field or another, so don't hesitate to reach out to other developers and ask questions. Your code is not perfect, so talk about best practices used in production and how you can improve on what you already have—communication should not be limited to your team, floor, or even building.</p><p>One bonus of my experience at Microsoft was discovering that a lot of developers, when not in a meeting or in the middle of an important assignment, are more than happy to help a fellow employee with a piece of advice or some code review.</p><h4>Plan the Small Details</h4><p>Before you even touch the keyboard to write your first line of code, outline the components of your application and have a general idea of how you’ll implement those components as well as how they’ll interact with each other. It is tempting to start coding and then add or modify features, but doing so will create more problems than it will solve.</p><h4>Build Small Prototypes</h4><p>FallFury is a complex project composed out of blocks such as:</p><ul><li>XML level/metadata reader and writer </li><li>The Share and Settings charm components </li><li>SpriteBatch sub-system </li><li>Level renderer </li><li>Screen sub-system </li><li>Menu interaction sub-system </li></ul><p>Each block is responsible for its own set of tasks and each can be individually tested with either mocked data or a loose connection to the existing codebase. The necessity for small prototypes comes from individual requirements tied to the platform and possible integration scenarios. For example, when I began development, I created a non-hybrid DirectX project, which meant that if I needed to introduce XAML integration, I had to rewrite small parts of my swap chain preparation stack as well as work with a lot of XAML content in the code-behind. The Settings charm integration heavily relied on XAML, and I would have had to write the popup and control-related code in C#.</p><p>Obviously, that was not an option, so I created a hybrid project instead and ported most of my code into the new solution. Lesson learned here: prototype—and prototype early—in order to make sure that what you plan to implement will be implemented in an efficient manner.</p><h4>Test Often, Test with Other People</h4><p>When working on an application, it is important to understand the needs and expectations of your target audience, and a big part of this is making sure that the application provides a way for the user to easily learn about an action without a helper booklet. The menu system is a good example of this in FallFury. As I was designing the buttons on my screens, I tried to implement the approach used in games such as Dance Central—the user simply slides the button-panel and it takes him to the screen that was linked to that specific button. However, as I was testing the application with the local development crowd, I noticed a pattern—people were attempting to simply tap the button instead of sliding it. To avoid this confusion, I added a pulsating arrow on the right side of the button in order to highlight the fact that the button should be displaced in order to be activated.</p><p>The XML level loading system is another example of how secondary testing improved FallFury. Initial element positioning relied on a given level length, as well as on a ration-based placement. For example, if I wanted to put a button in the middle of the screen, I could position it with a value, such as .5. The level loader would then translate this value relative to the screen size. Rick Barraza was creating some test levels when he notified me about a big flaw—as the level extended, some elements were mis-positioned by a large margin compared to the original intended location. This was because when a level length was reset, the ratio was applied on a larger/smaller value, and some elements would therefore overlap. Ultimately, I rewrote the level structure to rely on pixel values, and designed the level-length to calculate automatically based on the included elements and their size.</p><h4>Test on Different Hardware</h4><p>FallFury started with portable hardware in mind. Its original design targeted Windows 8 tablet devices, though it was later decided that the project should support desktop machines as well. That automatically added thousands of possible hardware combinations on which the game might potentially run. Here are just some of the test machines we got to use:</p><ul><li>Samsung Series 7 Slate </li><li>ARM Developer Tablet (Microsoft Surface) </li><li><a href="http://www.asus.com/Eee/Eee_Pad/Eee_Slate_EP121/">ASUS EP121 Slate</a> </li></ul><p>Each of these machines came with its own specific conditions that had to be accommodated. While Samsung Series 7 Slate featured an accelerometer, at the time of development the ASUS EP121 tablet did not have Windows 8 drivers for its sensor. When I sideloaded the game, I noticed that I could no longer control the character the way I wanted to. Also, though FallFury has keyboard controls, I had to develop controls for machines without keyboards. This is why I came up with the concept of touch-based, on-screen controls.</p><p>Moving on to the ARM device, first and foremost I noticed that my shader configurations were not compatible with the platform capabilities. All my testing was done on a machine that supported DirectX Feature Level 10, which was not the case for a low-power ARM machine that supports DirectX Feature Level 9.1. I had to work with some MSDN samples to find a way to properly modify the required shaders so they would work on Windows RT. ARM devices are built with battery life in mind. Therefore, their capabilities are reduced compared to those of a full-sized Windows tablet. This had an impact on the general game performance—some parts of the game, such as particle rendering, were working fine on a desktop machine, but were quite laggy on the ARM tablet. Knowing the possible source of the problem, I had to optimize the particle storage and rendering stack to ensure they didn’t affect the user experience on Windows RT hardware.</p><h4>There Is Never Enough Time - Learn To Cut</h4><p>When I started planning FallFury, I worked up a huge list of features. As the deadline approached, however, I noticed that I somewhat underestimated the allocated project time—a lot of time was spent on testing and eliminating bugs in existing features. That was the point at which I had to cut my feature set.</p><p>When designing the feature list for your app, make sure that you have a clear vision of which features get the priority and which can be cut if necessary. For example, FallFury was originally planned to be a multiplayer game. Although it was tempting to start working on it as such from the very beginning, I knew that it wasn’t a core feature and that it wouldn’t necessarily affect the general play experience on release day. Ultimately, multiplayer capability was dropped from initial development along with a number of other not-immediately-integral features.</p><h4>Expect the Unexpected</h4><p>When allocating time for the project, anticipate situations that might derail the process and cause a delay in the planned delivery date. It is easy to estimate that creating an accelerometer-based motion system will take you a day or two, but you also need to allow for the potential possibility of your code not working as expected, hardware accidents, natural disasters, etc. Doing so will help you focus on the right features at the right time while diminishing the risk of missing the deadline.</p><h4>Platform Samples Are the Best Documentation - Learn to Read Others’ Code</h4><p>While building the core of FallFury, I leveraged multiple features that hadn’t yet become mainstream among Windows developers. Therefore, the documentation was scarce and in some instances the only help I could get was internal. Luckily, Microsoft bundled hundreds of samples that demonstrate what the new platform can do. A lot of the development approaches gained during my internship were learned from looking at the official, publicly released sample code. The lesson here: if it's not on MSDN or blogs, check the official developer samples. For example, I used the <a href="http://code.msdn.microsoft.com/windowsapps/Direct3D-sprite-sample-97ae6262">DirectX sprite drawing sample</a> to see how to build a proper sprite rendering mechanism with behavior similar to the one available in XNA.</p><h4>Atomic Commits</h4><p>When I started, source control wasn’t new to me, but there were proper usage practices that I didn’t apply before the internship. One of them is atomic commits, which I learned from <a href="https://twitter.com/ClintRutkas">Clint Rutkas</a>.</p><p>With every new addition to the application, chances are something might go wrong. It could be a faulty third-party assembly, a misplaced class, or a broken reference that brings down the entire solution. If the commits include longer time intervals, for example, you will ultimately have to roll back to a build without a lot of the new functionality. Using atomic commits, however, you’ll be able to avoid unnecessary, redundant work in the case that something goes wrong during development.</p><h4>A Non-standard Approach Is Not Necessarily a Bad Approach</h4><p>For loading high scores, I needed the UI layout to display the registered items. To do so, I had could either use data binding or write a simple routine that would generate XAML items on the fly in the code-behind. Data binding is a pretty common practice among XAML developers, so my initial thought was to use that, but I would have had to create a C&#43;&#43; binding harness in addition to the existing data retrieval code. The second approach was much cleaner because it didn’t require me to rewrite or add much code. The lesson here: pick the best approach for the job and don’t blindly follow programming trends.</p><h4>Focus on the User Experience</h4><p>At the end of the day, the user doesn’t care whether you wrote the application in native DirectX or XNA, whether you applied the MVVM pattern, or whether you have easily readable code. The user cares about having a great time while playing the game, regardless of its backbone. It’s your goal as a developer to deliver that user experience and ensure that the user feels comfortable with the product. This means that the development cycle goes beyond simply writing code. In FallFury, levels are dynamic, which means the source code doesn’t necessarily need to be modified in order to create a different playable experience. But that experience matters in any case, and level design is a huge part of FallFury’s final product. Users need to be immersed in the game world, so levels must be planned in such as way that the user returns to the game and doesn’t abandon it after a couple of lost rounds.</p><h4>Conclusion</h4><p>FallFury was my first major project that I wrote almost entirely in C&#43;&#43;, targeting the newly released Windows 8 operating system. Although the development process was challenging, it was proven to be a great educational experience that taught me about the approaches and practices that are used internally at Microsoft.</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:cf5ded925e574af79c1fa14d01624d0b">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-12-Conclusions</comments>
      <itunes:summary>Project ConclusionsDeveloping FallFury was a fun and educational activity. Besides the fact that I got to work with an amazing team of people who were willing to assist me with the testing and development, I learned some important points about the development process as a whole and have outlined them in this article.&amp;nbsp; Check out the video for this article at http://channel9.msdn.com/Series/FallFury/Part-12-Project-Conclusion.&amp;nbsp; For a complete, offline version of this series, you may download a nicely formatted PDF of all the articles. Go Outside Your Comfort ZoneThis past summer, I decided to tackle a new challenge—game development. Never before had I built a game from the ground up. Moreover, as I could already find my way around C# code, I decided that I wanted to make C&amp;#43;&amp;#43; the language of choice, and so worked with DirectX instead of XNA. Additionally, the project needed to be constructed with Windows 8 as the target platform and I’d have to rely on the WinRT stack. The concepts were new to me, but I figured that learning about a new platform and a new language would be more interesting than sticking to my comfort zone. Through FallFury I extended my knowledge about pointers, trigonometry, how DirectX handles a lot of the graphics legwork, and how to write HLSL shaders. It was a challenging but very rewarding experience. CommunicateThe most important part of any project is communication. There are always people who know more than you in one field or another, so don&#39;t hesitate to reach out to other developers and ask questions. Your code is not perfect, so talk about best practices used in production and how you can improve on what you already have—communication should not be limited to your team, floor, or even building. One bonus of my experience at Microsoft was discovering that a lot of developers, when not in a meeting or in the middle of an important assignment, are more than happy to help a fellow employee with a piece of advice or some code </itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-12-Conclusions</link>
      <pubDate>Wed, 23 Jan 2013 23:57:48 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-12-Conclusions</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/f8eb/37473ed7-1ccd-4afc-834d-d99ae5b2f8eb/FallFuryPart12_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/f8eb/37473ed7-1ccd-4afc-834d-d99ae5b2f8eb/FallFuryPart12_220.jpg" height="124" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/f8eb/37473ed7-1ccd-4afc-834d-d99ae5b2f8eb/FallFuryPart12_512.jpg" height="289" width="512"></media:thumbnail>      
      <dc:creator>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</dc:creator>
      <itunes:author>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-12-Conclusions/RSS</wfw:commentRss>
      <category>C#</category>
      <category>C++</category>
      <category>Windows Store App</category>
    </item>
  <item>
      <title>Fall Fury: Part 11 - Hardware Testing &amp; Debugging</title>
      <description><![CDATA[<h3>Hardware Testing &amp; Debugging</h3><p>As previously mentioned, FallFury runs on multiple types of hardware as long as that hardware supports Windows 8. This article describes the project’s general testing and debugging process, including setting the debug configurations and remote debugging.</p><p>Check out the video for this article at <a href="http://channel9.msdn.com/Series/FallFury/Part-11-Hardware-Testing">http://channel9.msdn.com/Series/FallFury/Part-11-Hardware-Testing</a>.&nbsp; For a complete, offline version of this series, you may <a href="http://media.ch9.ms/coding4fun/fallfury/FallFury.pdf">download a nicely formatted PDF of all the articles</a>.</p><h4>Remote Debug</h4><p>When working on an application that targets different machines, it’s probably out of the question to install Visual Studio on each instance and move the solution from one source to another in order to run it and diagnose potential problems. Here is where <a href="http://www.microsoft.com/en-us/download/details.aspx?id=30674">Remote Tools for Visual Studio 2012</a> come into play. Microsoft offers you three separate builds—tools for x86 systems, x64 systems, and ARM systems—also known as Surface RT.</p><p>Once the tools are running on the machine you want to debug, you have two choices. You can either install the remote debugger as a service, allowing it to constantly run in the background, or you can use the debugger on a per-launch basis. From a developer perspective, the choice doesn’t affect how your application is executed on the remote machine. From a security perspective, however, you need to be sure that you properly configure it so that no unwanted apps are remotely deployed.</p><p>Now you can start the Remote Debugger Configuration Wizard:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image002%5B3%5D-8.jpg"><img title="clip_image002" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image002_thumb-9.jpg" alt="clip_image002" width="372" height="312" border="0"></a> <a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image004%5B3%5D-6.jpg"><img title="clip_image004" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image004_thumb-7.jpg" alt="clip_image004" width="333" height="312" border="0"></a></p><p>This works on both the initial start-up and also any subsequent launch as a way to easily and quickly set the necessary remote debugger settings. Specifically, it is useful to configure the machine’s network settings, allowing cross-domain communications for debugging purposes.</p><p>Once the wizard is completed, launch the Remote Debugger Monitor. Notice that it lists your machine name and the port on which it’s running. This is necessary for configuring the project to send the package to a remote machine instead of the local one:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image006%5B3%5D-4.jpg"><img title="clip_image006" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image006_thumb-5.jpg" alt="clip_image006" width="501" height="167" border="0"></a></p><p>The configuration depends on the network settings on both the local machine and the subnet as a whole. For example, in some cases, and especially on domain-joined machines, remote debugging is better done with the authentication disabled. Windows Authentication is used by default.</p><p>Since FallFury is a C&#43;&#43; project, the configuration for a remote session is different than, say, that of a C# Windows Store application. To configure the session, right click on the project in <strong>Solution Explorer</strong> and open the <strong>Debugging</strong> section. Make sure that Remote Machine is selected as the type of debugger to launch:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image008%5B3%5D-5.jpg"><img title="clip_image008" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image008_thumb-6.jpg" alt="clip_image008" width="640" height="142" border="0"></a></p><p>Next, specify the machine name as well as whether the current session will require authentication:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image010%5B3%5D-3.jpg"><img title="clip_image010" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image010_thumb-4.jpg" alt="clip_image010" width="640" height="196" border="0"></a></p><p>If you cannot specify the machine name, use the direct IPv4 address of that computer, minus the port <a>(unless you’ve explicitly set it to a port other than 4016, which is the assumed default).</a> Once the source machine connects to the remote one, you will see Visual Studio performing the deployment:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image012%5B3%5D-5.jpg"><img title="clip_image012" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image012_thumb-5.jpg" alt="clip_image012" width="640" height="108" border="0"></a></p><h4>Configurations</h4><p>As a matter of convenience, it is always good to have different debug configurations that will define how your projects are built, especially if the project targets multiple platforms (such as ARM and x86). Visual Studio provides a <a href="http://msdn.microsoft.com/en-us/library/kwybya3w%28v=vs.80%29.aspx">Configuration Manager</a> that can be accessed from the debug target dropdown:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image013%5B3%5D.png"><img title="clip_image013" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image013_thumb.png" alt="clip_image013" width="300" height="199" border="0"></a></p><p>FallFury includes two separate projects—the game core, and the C#-based XML reader. Both need to be explicitly associated with separate target platforms in order to be correctly debugged. For that, profiles were created for both local and remote sessions:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image014%5B3%5D.png"><img title="clip_image014" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image014_thumb.png" alt="clip_image014" width="640" height="186" border="0"></a></p><p>As with standard Debug/Release configurations, the ones shown above determine whether the project will carry debug symbols and support debugging commands. It is important to mention that as you switch configurations, you must be careful how you configure the graphic shaders. For each shader in the container folder, explicitly set the HLSL shader type and model. Otherwise the application deployment will fail:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image016%5B3%5D-3.jpg"><img title="clip_image016" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image016_thumb-4.jpg" alt="clip_image016" width="640" height="144" border="0"></a></p><h4>Remote Profiling</h4><p>Last but not least, when working with different hardware configurations it might be useful to perform application profiling or performance review. Fortunately, Visual Studio also provides this capability through the <a href="http://msdn.microsoft.com/en-us/library/hh977161.aspx"><strong>vsperf</strong></a> tool, which is already integrated in the IDE if you are using Visual Studio 2012 Professional or above.</p><p>To initiate a profiling session on a remote device, the Remote Debugger Monitor must be active. Make sure that the <strong>Remote Machine</strong> debug target is selected, and go to <strong>Analyze &gt; Start Performance Analysis</strong>:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image017%5B3%5D.png"><img title="clip_image017" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image017_thumb.png" alt="clip_image017" width="404" height="83" border="0"></a></p><p>On the remote machine, allow the <strong>vsperf</strong> process to run with administrative privileges. Once the profiling session completes and the data is analyzed, you can review the same performance indicators as you would when having a standard application run the profiler on the local machine:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image019%5B3%5D.jpg"><img title="clip_image019" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image019_thumb.jpg" alt="clip_image019" width="640" height="312" border="0"></a></p><h4>Conclusion</h4><p>Testing hardware outside the boundaries of a desktop machine is often a necessity, especially if the application relies on specific sensors, such as NFC, touch, or accelerometer. The remote debugging process is fairly streamlined and intuitive, with developing a proper network configuration allowing communication between machines requiring the most significant amount of effort. If you have problems getting the debugger to work, <a href="http://msdn.microsoft.com/en-us/library/bt727f1t.aspx">consult this article on MSDN</a>.</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:4e4e6ed2c2cc4a98946aa14d0161797b">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-11-Hardware-Testing--Debugging</comments>
      <itunes:summary>Hardware Testing &amp;amp; DebuggingAs previously mentioned, FallFury runs on multiple types of hardware as long as that hardware supports Windows 8. This article describes the project’s general testing and debugging process, including setting the debug configurations and remote debugging. Check out the video for this article at http://channel9.msdn.com/Series/FallFury/Part-11-Hardware-Testing.&amp;nbsp; For a complete, offline version of this series, you may download a nicely formatted PDF of all the articles. Remote DebugWhen working on an application that targets different machines, it’s probably out of the question to install Visual Studio on each instance and move the solution from one source to another in order to run it and diagnose potential problems. Here is where Remote Tools for Visual Studio 2012 come into play. Microsoft offers you three separate builds—tools for x86 systems, x64 systems, and ARM systems—also known as Surface RT. Once the tools are running on the machine you want to debug, you have two choices. You can either install the remote debugger as a service, allowing it to constantly run in the background, or you can use the debugger on a per-launch basis. From a developer perspective, the choice doesn’t affect how your application is executed on the remote machine. From a security perspective, however, you need to be sure that you properly configure it so that no unwanted apps are remotely deployed. Now you can start the Remote Debugger Configuration Wizard:   This works on both the initial start-up and also any subsequent launch as a way to easily and quickly set the necessary remote debugger settings. Specifically, it is useful to configure the machine’s network settings, allowing cross-domain communications for debugging purposes. Once the wizard is completed, launch the Remote Debugger Monitor. Notice that it lists your machine name and the port on which it’s running. This is necessary for configuring the project to send the package to a remote ma</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-11-Hardware-Testing--Debugging</link>
      <pubDate>Wed, 23 Jan 2013 23:57:44 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-11-Hardware-Testing--Debugging</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/d2bf/2dea3e0d-559c-4efb-ae2d-a2c49c20d2bf/FallFuryPart11_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/d2bf/2dea3e0d-559c-4efb-ae2d-a2c49c20d2bf/FallFuryPart11_220.jpg" height="124" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/d2bf/2dea3e0d-559c-4efb-ae2d-a2c49c20d2bf/FallFuryPart11_512.jpg" height="289" width="512"></media:thumbnail>      
      <dc:creator>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</dc:creator>
      <itunes:author>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</itunes:author>
      <slash:comments>3</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-11-Hardware-Testing--Debugging/RSS</wfw:commentRss>
      <category>C#</category>
      <category>C++</category>
      <category>DirectX</category>
      <category>Windows Store App</category>
    </item>
  <item>
      <title>Fall Fury: Part 10 - Charms</title>
      <description><![CDATA[<h3>Charms</h3><p>With the release of the Windows 8 operating system, applications are now able to easily integrate with each other and have a unified way to control their workflow through unique <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh464906.aspx">system-wide contracts</a> called <a href="http://blogs.msdn.com/b/going_metro/archive/2012/04/22/integrating-with-windows-8-charms-amp-contracts.aspx">Charms</a>. Out of the multitude of available options, FallFury leverages two charms—Share contract and Settings. This article describes how the integration is implemented.</p><p>Check out the video for this article at <a href="http://channel9.msdn.com/Series/FallFury/Part-10-Charms">http://channel9.msdn.com/Series/FallFury/Part-10-Charms</a>&nbsp;.&nbsp; For a complete, offline version of this series, you may <a href="http://media.ch9.ms/coding4fun/fallfury/FallFury.pdf">download a nicely formatted PDF of all the articles</a>.</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image002%5B3%5D-7.jpg"><img title="clip_image002" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image002_thumb-8.jpg" alt="clip_image002" width="640" height="362" border="0"></a></p><h4>The Share Contract</h4><p>When a user achieves a specific score in the game, he might decide to share it with his social circle. In Charms, that’s the purpose of the Share contract, which integrates directly with the OS.</p><p>Windows Store applications have the capability to expose their sharing capabilities and register as <a href="http://code.msdn.microsoft.com/windowsapps/Sharing-Content-Target-App-e2689782">a share target</a>. For example, if there is a Twitter client out, it can register itself as an app through which content can be shared. FallFury, on the other hand, acts as a consumer that aggregates existing share targets and lets the user pick the one through which he wants to let the message out:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image004%5B3%5D-5.jpg"><img title="clip_image004" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image004_thumb-6.jpg" alt="clip_image004" width="640" height="192" border="0"></a></p><p>Let’s take a look at how this process is built in the code-behind. The core is located in <strong>DirectXPage.xaml.cpp</strong>—the class responsible for XAML content manipulation in FallFury. First and foremost, you need to get the current instance of the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.datatransfer.datatransfermanager">DataTransferManager</a> class:</p><p><pre class="brush: cpp">
auto dataTransferManager = Windows::ApplicationModel::DataTransfer::DataTransferManager::GetForCurrentView();
</pre></p><p>Consider this a proxy that allows you to pass content between your app and other Windows Store apps that are executed in the context of the same sandbox. As the instance is obtained, hook it to the <strong>DataRequested</strong> event handler that will handle the scenario where the user invoked the sharing capability:</p><p><pre class="brush: cpp">
dataTransferManager-&gt;DataRequested &#43;= ref new 
    TypedEventHandler&lt;Windows::ApplicationModel::DataTransfer::DataTransferManager^,
    Windows::ApplicationModel::DataTransfer::DataRequestedEventArgs^&gt;(this, &amp;DirectXPage::OnShareDataRequested);
</pre></p><p>&nbsp;</p><p>In the <strong>OnShareDataRequested</strong>, specify the information that goes into the sharing popup:</p><p><pre class="brush: cpp">
void DirectXPage::OnShareDataRequested(Windows::ApplicationModel::DataTransfer::DataTransferManager^ manager,Windows::ApplicationModel::DataTransfer::DataRequestedEventArgs^ params)
{
    auto request = params-&gt;Request;
    request-&gt;Data-&gt;Properties-&gt;Title = &quot;Share Score&quot;;
    request-&gt;Data-&gt;Properties-&gt;Description = &quot;Tell your friends how much you scored in [DEN'S PROJECT]!&quot;;
    request-&gt;Data-&gt;SetText(&quot;I just scored &quot; &#43; StaticDataHelper::Score.ToString() &#43; &quot; in [DEN'S PROJECT]! Beat me! http://dennisdel.com&quot;);
}
</pre></p><p>&nbsp;</p><p>From that point, the control is in the user’s hand. The application cannot force the share, so unless you implement a direct API hook to a social service, the Share charm will only expose the endpoints available for sharing and will let you set the shareable content. You also don’t have to worry about the way the content will be shared—that will be handled by the target application:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image006%5B3%5D-3.jpg"><img title="clip_image006" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image006_thumb-4.jpg" alt="clip_image006" width="571" height="411" border="0"></a></p><p>You can show the popup triggered by the Share charm from your application without having the user open the Charms Bar. To do this, call the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.datatransfer.datatransfermanager.showshareui">ShowShareUI</a> method:</p><p><pre class="brush: cpp">
void DirectXPage::ShareTopScore_Selected(MenuItem^ sender, Platform::String^ params)
{
    Windows::ApplicationModel::DataTransfer::DataTransferManager::ShowShareUI();
}
</pre></p><p>&nbsp;</p><p>This is exactly what the Share button does in the screenshot above. You should make this behavior predictable.</p><h4>The Settings Charm</h4><p>As you just saw, integrating basic sharing capabilities in FallFury is not too complicated. Working with settings is also a fairly easy task, though it involves some XAML work. While with sharing capabilities the work focused mostly on OS-based endpoints and application-specific popups, settings allow for full control over how they’re displayed.</p><p>For all Windows Store applications, settings should be handled via the Settings charm and not through dedicated application screens. Consider which settings that directly affect the user experience might be changed in FallFury:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image008%5B3%5D-4.jpg"><img title="clip_image008" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image008_thumb-5.jpg" alt="clip_image008" width="506" height="230" border="0"></a></p><ul><li><strong>Music and SFX</strong> – the user can enable or disable music and sound effects, as well as control their volume. </li><li><strong>Accelerometer</strong> – depending on personal preferences, the user might decide to disable the accelerometer (it is enabled by default). The accelerometer can also be inverted—if the device is tilted to the right, the character will move to the left and vice-versa. Last but not least, even with dynamic screen rotation enabled on the device, the user can disable that rotation on the application level and lock the screen to one orientation, such as portrait or landscape. </li><li><strong>Character Movement</strong> – the character can be easily controlled via touch (swipe) or mouse. This behavior is enabled by default, but if the user decides to only use the mouse to direct shells, he can easily disable this feature here. </li></ul><p>As seen in the image above, the operating system provides the basic shell used to list the possible settings. Once one option is selected, however, further UI displays are delegated to the developer.</p><p>As with the share UI, the settings UI can be shown to the user from the application and not from the Charms Bar. Here is how to do this:</p><p><pre class="brush: cpp">
void DirectXPage::Settings_Selected(MenuItem^ sender, Platform::String^ params)
{
    SettingsPane::GetForCurrentView()-&gt;Show();
}
</pre></p><p>&nbsp;</p><p><a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.applicationsettings.settingspane">SettingsPane</a> is the core class that handles the settings display. It does not control how settings are stored or activated. When the main page loads, you need to make sure that you hook the current <strong>SettingsPane</strong> to a <strong>CommandRequested</strong> event handler. It will be triggered when the Settings capability is invoked:</p><p><pre class="brush: cpp">
SettingsPane::GetForCurrentView()-&gt;CommandsRequested &#43;= ref new TypedEventHandler&lt;SettingsPane^, SettingsPaneCommandsRequestedEventArgs^&gt;(this, &amp;DirectXPage::OnSettingsRequested);
</pre></p><p><strong>OnSettingsRequested</strong> is the function where the core setting selections are defined and hooked to their own event handlers:</p><p><pre class="brush: cpp">
void DirectXPage::OnSettingsRequested(Windows::UI::ApplicationSettings::SettingsPane^ settingsPane, Windows::UI::ApplicationSettings::SettingsPaneCommandsRequestedEventArgs^ eventArgs)
{
    if (m_renderer-&gt;CurrentGameState == GameState::GS_PLAYING)
            StaticDataHelper::IsPaused = true;
    
    UICommandInvokedHandler^ handler = ref new UICommandInvokedHandler(this, &amp;DirectXPage::OnSettingsSelected);
    
        SettingsCommand^ generalCommand = ref new SettingsCommand(&quot;musicSfx&quot;, &quot;Music &amp; SFX&quot;, handler);
        eventArgs-&gt;Request-&gt;ApplicationCommands-&gt;Append(generalCommand);
    
    SettingsCommand^ accelerometerCommand = ref new SettingsCommand(&quot;accelerometer&quot;, &quot;Accelerometer&quot;, handler);
    eventArgs-&gt;Request-&gt;ApplicationCommands-&gt;Append(accelerometerCommand);
    
    SettingsCommand^ charMovementCommand = ref new SettingsCommand(&quot;charMovement&quot;, &quot;Character Movement&quot;, handler);
    eventArgs-&gt;Request-&gt;ApplicationCommands-&gt;Append(charMovementCommand);
}
</pre></p><p>Each <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.applicationsettings.settingscommand">SettingsCommand</a> is an item in the list displayed in the settings pane. When one is selected, <strong>OnSettingsSelected</strong> is called:</p><p><pre class="brush: cpp">
void DirectXPage::OnSettingsSelected(Windows::UI::Popups::IUICommand^ command)
{
    if (command-&gt;Id-&gt;ToString() == &quot;musicSfx&quot;)
    {
        stkMusicSfx-&gt;Width = 346.0f;
        grdSubMusicSfx-&gt;Height = m_renderer-&gt;m_renderTargetSize.Height;
        stkMusicSfx-&gt;IsOpen = true;
    }
    else if (command-&gt;Id-&gt;ToString() == &quot;accelerometer&quot;)
    {
        stkAccelerometerSettings-&gt;Width = 346.0f;
        grdAccelerometerSettings-&gt;Height = m_renderer-&gt;m_renderTargetSize.Height;
        stkAccelerometerSettings-&gt;IsOpen = true;
    }
    else if (command-&gt;Id-&gt;ToString() == &quot;charMovement&quot;)
    {
        stkCharacterMovement-&gt;Width = 346.0f;
        grdCharacterMovement-&gt;Height = m_renderer-&gt;m_renderTargetSize.Height;
        stkCharacterMovement-&gt;IsOpen = true;
    }

    WindowActivationToken = Window::Current-&gt;Activated &#43;= ref new WindowActivatedEventHandler(this, &amp;DirectXPage::OnWindowActivated);
}
</pre></p><p>Looking back at <strong>OnSettingsRequested</strong>, each command has a string identifier. When a command is invoked, that string identifier is returned through the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.popups.iuicommand">IUICommand</a> instance in the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.popups.iuicommand.id">Id</a> property. Based on that, I decided which popups to open. Since each has a similar structure, I am going to cover the implementation of just one—<strong>Music &amp; SFX</strong>.</p><p>Here is what the end result looks like:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image010%5B3%5D-2.jpg"><img title="clip_image010" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image010_thumb-3.jpg" alt="clip_image010" width="640" height="461" border="0"></a></p><p>The panel on the left is a <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.primitives.popup">Popup</a>, with two <a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.controls.primitives.togglebutton">ToggleButton</a> controls used to enable or disable generic music and sound effects. There are also two <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.slider">Slider</a> controls that are used to adjust the volume. The XAML for the above layout looks like this:</p><p><pre class="brush: xml">
&lt;Popup HorizontalAlignment=&quot;Right&quot; IsLightDismissEnabled=&quot;True&quot; x:Name=&quot;stkMusicSfx&quot; &gt;
    &lt;Grid Background=&quot;Black&quot; x:Name=&quot;grdSubMusicSfx&quot;  Width=&quot;346&quot;&gt;
        &lt;Grid.Transitions&gt;
            &lt;TransitionCollection&gt;
                &lt;RepositionThemeTransition /&gt;
            &lt;/TransitionCollection&gt;
        &lt;/Grid.Transitions&gt;

        &lt;Grid.RowDefinitions&gt;
            &lt;RowDefinition Height=&quot;120&quot;&gt;&lt;/RowDefinition&gt;
            &lt;RowDefinition Height=&quot;*&quot;&gt;&lt;/RowDefinition&gt;
        &lt;/Grid.RowDefinitions&gt;

        &lt;StackPanel Grid.Row=&quot;0&quot; Orientation=&quot;Horizontal&quot; Margin=&quot;24,12,0,0&quot; &gt;
            &lt;Button Margin=&quot;0&quot; VerticalAlignment=&quot;Center&quot; x:Name=&quot;dismissAudioSettings&quot; Click=&quot;dismissAudioSettings_Click&quot; Style=&quot;{StaticResource BackButtonStyle}&quot;&gt;&lt;/Button&gt;
            &lt;TextBlock Margin=&quot;12,0,0,12&quot; Height=&quot;Auto&quot; VerticalAlignment=&quot;Center&quot; Text=&quot;Music &amp;amp; SFX&quot; Style=&quot;{StaticResource SubheaderTextStyle}&quot;&gt;&lt;/TextBlock&gt;
        &lt;/StackPanel&gt;

        &lt;StackPanel Grid.Row=&quot;1&quot; Margin=&quot;24,24,0,0&quot;&gt;
            &lt;StackPanel&gt;
                &lt;TextBlock Text=&quot;Music&quot; Style=&quot;{StaticResource BodyTextStyle}&quot;&gt;&lt;/TextBlock&gt;
                &lt;TextBlock  Width=&quot;346&quot; Text=&quot;This includes the theme track and level background music.&quot; Style=&quot;{StaticResource CaptionTextStyle}&quot; TextWrapping=&quot;Wrap&quot; Margin=&quot;0,12,12,12&quot; &gt;&lt;/TextBlock&gt;
                &lt;ToggleSwitch x:Name=&quot;tglMusic&quot; Toggled=&quot;tglMusic_Toggled&quot; IsOn=&quot;{Binding ElementName=XAMLPage,Path=MusicEnabled}&quot; Margin=&quot;-6,0,0,0&quot;&gt;&lt;/ToggleSwitch&gt;
            &lt;/StackPanel&gt;

            &lt;StackPanel Margin=&quot;0,24,0,0&quot;&gt;
                &lt;TextBlock Text=&quot;Music Volume&quot; Style=&quot;{StaticResource BodyTextStyle}&quot;&gt;&lt;/TextBlock&gt;
                &lt;Slider x:Name=&quot;sldMusicVolume&quot; ValueChanged=&quot;sldMusicVolume_ValueChanged&quot; Value=&quot;{Binding ElementName=XAMLPage,Path=MusicVolume, Mode=TwoWay}&quot; Minimum=&quot;0&quot; Maximum=&quot;100&quot; Margin=&quot;0,0,12,0&quot;&gt;&lt;/Slider&gt;
            &lt;/StackPanel&gt;

            &lt;StackPanel Margin=&quot;0,24,0,0&quot;&gt;
                &lt;TextBlock Text=&quot;Sound Effects&quot; Style=&quot;{StaticResource BodyTextStyle}&quot;&gt;&lt;/TextBlock&gt;
                &lt;TextBlock Width=&quot;346&quot; Text=&quot;Includes sounds played during the game (e.g. explosions).&quot; Style=&quot;{StaticResource CaptionTextStyle}&quot; TextWrapping=&quot;Wrap&quot; Margin=&quot;0,12,12,12&quot; &gt;&lt;/TextBlock&gt;
                &lt;ToggleSwitch x:Name=&quot;tglSFX&quot; Toggled=&quot;tglSFX_Toggled&quot; IsOn=&quot;{Binding ElementName=XAMLPage,Path=SFXEnabled}&quot; Margin=&quot;-6,0,0,0&quot;&gt;&lt;/ToggleSwitch&gt;
            &lt;/StackPanel&gt;

            &lt;StackPanel Margin=&quot;0,24,0,0&quot;&gt;
                &lt;TextBlock Text=&quot;SFX Volume&quot; Style=&quot;{StaticResource BodyTextStyle}&quot;&gt;&lt;/TextBlock&gt;
                &lt;Slider x:Name=&quot;sldSFXVolume&quot; ValueChanged=&quot;sldSFXVolume_ValueChanged&quot; Value=&quot;{Binding ElementName=XAMLPage,Path=SFXVolume, Mode=TwoWay}&quot; Minimum=&quot;0&quot; Maximum=&quot;100&quot; Margin=&quot;0,0,12,0&quot;&gt;&lt;/Slider&gt;
            &lt;/StackPanel&gt;

        &lt;/StackPanel&gt;

    &lt;/Grid&gt;
&lt;/Popup&gt;
</pre></p><p>For every Popup instance used for settings, make sure that <strong>IsLightDismissEnabled</strong> is set to true. This allows the user to dismiss the panel with a touch outside its boundaries, just like the stock system panels. Other than that, you are working with the standard XAML control set and can include virtually anything in your settings.</p><p>Notice, that the switches and sliders are bound to internal properties, such as <strong>SFXEnabled</strong> and <strong>MusicEnabled</strong>, that perform the binding <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh700353.aspx">via dependency property references</a>:</p><p><pre class="brush: cpp">
DependencyProperty^ DirectXPage::_musicEnabled = DependencyProperty::Register(&quot;MusicEnabled&quot;, 
bool::typeid, DirectXPage::typeid, nullptr);
DependencyProperty^ DirectXPage::_sfxEnabled = DependencyProperty::Register(&quot;SFXEnabled&quot;, 
bool::typeid, DirectXPage::typeid, nullptr);
</pre></p><p>&nbsp;</p><p>The properties themselves are declared in the <strong>DirectXPage</strong> header file:</p><p><pre class="brush: csharp">
static property DependencyProperty^ SFXVolumeProperty
{
    DependencyProperty^ get() { return _sfxVolume; }
}
property int SFXVolume
{
    int get() { return (int)GetValue(SFXVolumeProperty); }
    void set(int value) 
    { 
        SetValue(SFXVolumeProperty, value);
    }
}

static property DependencyProperty^ MusicVolumeProperty
{
    DependencyProperty^ get() { return _musicVolume; }
}
property int MusicVolume
{
    int get() { return (int)GetValue(MusicVolumeProperty); }
    void set(int value) 
    { 
        SetValue(MusicVolumeProperty, value);
    }
}
</pre></p><p>Let’s take a quick look at how settings are stored. I have a class called <strong>SettingsHelper</strong> that allows me to save, read, and check if specific settings exist. Here is the implementation:</p><p><pre class="brush: cpp">
#include &quot;pch.h&quot;
#include &quot;SettingsHelper.h&quot;

using namespace Windows::Storage;
using namespace Coding4Fun::FallFury::Helpers;

SettingsHelper::SettingsHelper(void)
{
}

void SettingsHelper::Save(Platform::String^ key, Platform::Object^ value)
{
    ApplicationDataContainer^ localSettings = ApplicationData::Current-&gt;LocalSettings;
    auto values = localSettings-&gt;Values;

    values-&gt;Insert(key, value);
}

Platform::Object^ SettingsHelper::Read(Platform::String^ key)
{
    ApplicationDataContainer^ localSettings = ApplicationData::Current-&gt;LocalSettings;
    auto values = localSettings-&gt;Values;

    return values-&gt;Lookup(key);
}

bool SettingsHelper::Exists(Platform::String^ key)
{
    ApplicationDataContainer^ localSettings = ApplicationData::Current-&gt;LocalSettings;
    auto values = localSettings-&gt;Values;

    return values-&gt;HasKey(key);
}
</pre></p><p>&nbsp;</p><p>It is clear that storage and retrieval heavily relies on the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdatacontainer.aspx">ApplicationDataContainer</a> class, the container class for local settings that eliminates the need for the developer to create his own setting files, instead delegating this task to the OS and utilizing a centralized storage for all Windows Store applications.</p><p>A typical scenario that utilizes the class above is executed when the toggle that manages the sound effects is switched:</p><p><pre class="brush: cpp">
void DirectXPage::tglSFX_Toggled(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    SettingsHelper::Save(&quot;sfxEnabled&quot;, tglSFX-&gt;IsOn);
    SFXEnabled = tglSFX-&gt;IsOn;
    AudioManager::IsSFXStarted = SFXEnabled;

    if (SFXEnabled)
    {
        AudioManager::AudioEngineInstance.StartSFX();
    }
    else
    {
        AudioManager::AudioEngineInstance.SuspendSFX();
    }
}
</pre></p><p>&nbsp;</p><p>The Boolean value above will be automatically serialized and stored. The files will be located at <strong>C:\Users\YOUR_USER_NAME\AppData\Local\Packages\PACKAGE_ID\Settings\settings.dat:</strong></p><p>&nbsp;</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image012%5B3%5D-4.jpg"><img title="clip_image012" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image012_thumb-4.jpg" alt="clip_image012" width="640" height="192" border="0"></a></p><h4>Conclusion</h4><p>Implementing sharing through the OS channel in Windows 8 is extremely easy seeing as the developer does not necessarily have to worry about connecting the app to third-party API endpoints. Instead, the user controls the sharing, allowing flexibility of choice without requiring a major addition to the existing code base. It’s hard to predict which services might appear, and modifying the app to support each one of them would be next to impossible otherwise.</p><p>You can read more about settings in Windows Store applications <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh770544.aspx">here</a>.</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:41450e373f904b80834ba14d01612a58">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-10-Charms</comments>
      <itunes:summary>CharmsWith the release of the Windows 8 operating system, applications are now able to easily integrate with each other and have a unified way to control their workflow through unique system-wide contracts called Charms. Out of the multitude of available options, FallFury leverages two charms—Share contract and Settings. This article describes how the integration is implemented. Check out the video for this article at http://channel9.msdn.com/Series/FallFury/Part-10-Charms&amp;nbsp;.&amp;nbsp; For a complete, offline version of this series, you may download a nicely formatted PDF of all the articles.  The Share ContractWhen a user achieves a specific score in the game, he might decide to share it with his social circle. In Charms, that’s the purpose of the Share contract, which integrates directly with the OS. Windows Store applications have the capability to expose their sharing capabilities and register as a share target. For example, if there is a Twitter client out, it can register itself as an app through which content can be shared. FallFury, on the other hand, acts as a consumer that aggregates existing share targets and lets the user pick the one through which he wants to let the message out:  Let’s take a look at how this process is built in the code-behind. The core is located in DirectXPage.xaml.cpp—the class responsible for XAML content manipulation in FallFury. First and foremost, you need to get the current instance of the DataTransferManager class: 
auto dataTransferManager = Windows::ApplicationModel::DataTransfer::DataTransferManager::GetForCurrentView();
 Consider this a proxy that allows you to pass content between your app and other Windows Store apps that are executed in the context of the same sandbox. As the instance is obtained, hook it to the DataRequested event handler that will handle the scenario where the user invoked the sharing capability: 
dataTransferManager-&amp;gt;DataRequested &amp;#43;= ref new 
    TypedEventHandler&amp;lt;Windows::ApplicationM</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-10-Charms</link>
      <pubDate>Wed, 23 Jan 2013 23:57:40 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-10-Charms</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/d462/4039d0c3-2c48-4570-98d7-56de07f1d462/FallFuryPart10_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/d462/4039d0c3-2c48-4570-98d7-56de07f1d462/FallFuryPart10_220.jpg" height="124" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/d462/4039d0c3-2c48-4570-98d7-56de07f1d462/FallFuryPart10_512.jpg" height="289" width="512"></media:thumbnail>      
      <dc:creator>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</dc:creator>
      <itunes:author>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-10-Charms/RSS</wfw:commentRss>
      <category>C#</category>
      <category>C++</category>
      <category>DirectX</category>
      <category>Windows Store App</category>
    </item>
  <item>
      <title>Fall Fury: Part 9 - Particle System</title>
      <description><![CDATA[<h3>Particle System</h3><p>During gameplay there are scenarios during which users need to be visually notified that something has happened, such as a collision with an obstacle or an enemy shell. One way to do this is by having explosion or item breaking simulation, which brings us to the next large component in FallFury—the sprite-based particle system. It doesn’t offer as much power as a full-fledged particle system would, but it allows for effects that fit well within the overall theme and layout of the game.</p><p>Check out the video for this article at <a href="http://channel9.msdn.com/Series/FallFury/Part-9-Particle-System">http://channel9.msdn.com/Series/FallFury/Part-9-Particle-System</a>&nbsp;.&nbsp; For a complete, offline version of this series, you may <a href="http://media.ch9.ms/coding4fun/fallfury/FallFury.pdf">download a nicely formatted PDF of all the articles</a>.</p><h4>The Core</h4><p><strong>ParticleSystem</strong> is the dedicated folder in the project that contains everything needed to render multiple textures at once and displace them to create the desired effect:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image001%5B3%5D.png"><img title="clip_image001" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image001_thumb.png" alt="clip_image001" width="353" height="343" border="0"></a></p><p>A single particle carries information regarding its size, position, velocity, color shading, rotation, circular velocity, and scale. As with any other rendered entity, it has a bounding box that can be used to detect its intersection with other elements on the screen. In FallFury, this functionality is not used.</p><p>Its structure is as follows:</p><p><pre class="brush: cpp">
#pragma once
#include &quot;pch.h&quot;
struct Particle
{
    Particle(float2 size);
    Particle(float2 size, float4 shading);
    float2 Size;
    float2 Position;
    float2 Velocity;
    float4 Shading;
    float Rotation;
    float RotationVelocity;
    float Scale;
    bool IsWithinScreenBoundaries(float x, float y, Windows::Foundation::Rect screenBounds);
    Windows::Foundation::Rect GetBoundingBox();
};
</pre></p><p>The <strong>Particle</strong> class also happens to have two constructors—one that sets the particle to have the default shading, effectively removing the effect, and one where shading is dynamic. Note that a particle on its own doesn’t do much—it neither carries the associated texture nor has an internal loop that can be used in any given application part to display it.</p><p>The next core class is <strong>ParticleSet</strong>. It is used as a container for all the particles associated with a specific effect. For example, if I want to create flying stuffing when the bear hits an obstacle, I create a new ParticleSet instance and define the necessary particle properties:</p><ul><li><strong>Lifespan</strong> – a particle set does not constantly animate. It displays the particles for a limited amount of time, and displaces them by the given velocity values, and then self-destructs. </li><li><strong>Texture</strong> – all particles in a <strong>ParticleSet</strong> have the same texture. Going back to the stuffing example, there is a single PNG file used to render multiple variable-sized particles on collision. </li><li><strong>IsAlive </strong>– this is the flag that shows whether the particle set should be rendered in the first place. If it is set to <strong>false</strong> then, regardless of the conditions, this <strong>ParticleSet</strong> instance is ignored. </li><li><strong>ShouldScale </strong>– this flag determines whether particles will automatically increase their scale as they are being displaced, creating the effect of a particle approaching the screen. This effect is applied to each particle in the set. </li></ul><p>The container class is used to update the particles through the Update function:</p><p><pre class="brush: cpp">
void ParticleSet::Update(float timeDelta)
{
    float quat = _lifespan / 0.016f;
    float decrement = 1.0f / quat;
    
    if (_totalTime &lt;= _lifespan &amp;&amp; _isAlive)
    {
        _totalTime &#43;= timeDelta;
        
        for (auto particle = _particles.begin(); particle != _particles.end(); particle&#43;&#43;)
        {
            if (_shouldScale)
                particle-&gt;Scale &#43;= 0.2f;
            
            particle-&gt;Shading.a -= decrement;
            particle-&gt;Position = float2(particle-&gt;Position.x &#43; particle-&gt;Velocity.x,
                            particle-&gt;Position.y &#43; particle-&gt;Velocity.y);
            
            if (!_shouldScale)
                particle-&gt;Rotation &#43;= particle-&gt;RotationVelocity;
        }
    }
    else
    {
        _totalTime = 0.0f;
        _isAlive = false;
    }
}
</pre></p><p>As it relies on the <strong>_isAlive</strong> flag, the <strong>Update</strong> loop is only used when the particle displacement is activated via the <strong>Activate</strong> function:</p><p><pre class="brush: cpp">
void ParticleSet::Activate(float2 position, float2 velocity, bool randomize, bool scale)
{
    for (auto particle = _particles.begin(); particle != _particles.end(); particle&#43;&#43;)
    {
        particle-&gt;Position = position;

        if (randomize)
            particle-&gt;Velocity = float2(RandFloat(-5.0f,5.0f), RandFloat(-5.0f, 5.0f));
        else
            particle-&gt;Velocity = float2(velocity.x &#43; RandFloat(-0.6f, 0.6f), velocity.y &#43; RandFloat(-0.6f, 0.6f));;
    }

    _shouldScale = scale;
    _isAlive = true;
}
</pre></p><p>When a set is activated, several user-defined parameters come into play. The position is set no matter what and is used to create the source point from which the particles start appearing. The velocity, on the other hand, can be randomized between the values of <em>-5</em> and <em>5</em> pixels per update loop, on both the X-axis and the Y-axis. If randomized, large amount of particles will create an explosion that starts from the center point and expands towards all quadrants. When the velocity is not randomized, it creates a triangular expansion grid on which particles deviate from the center point in one of the given directions:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image003%5B3%5D-1.png"><img title="clip_image003" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image003_thumb-1.png" alt="clip_image003" width="640" height="235" border="0"></a></p><p>When it’s time to render the particles, the sprite batch associated with the current game screen is used to pass a texture for each particle registered in the set:</p><p><pre class="brush: cpp">
void ParticleSet::Render(SpriteBatch ^spriteBatch)
{
    for (auto particle = _particles.begin(); particle != _particles.end(); particle&#43;&#43;)
        {
        if (GamePlayScreen::Manager-&gt;IsWithinScreenBoundaries(particle-&gt;Position))
                    spriteBatch-&gt;Draw(_texture.Get(), particle-&gt;Position, PositionUnits::DIPs,
                    particle-&gt;Size * particle-&gt;Scale, SizeUnits::Pixels, particle-&gt;Shading, particle-&gt;Rotation);
        }
}
</pre></p><p>Although there is no flag check inside the Render method that would make sure that the set is alive, this can be done outside of it by calling <strong>IsAlive</strong>, which will return the flag value:</p><p><pre class="brush: cpp">
bool ParticleSet::IsAlive()
{
    return _isAlive;
}
</pre></p><p>&nbsp;</p><p>Let’s now take a look at the class that managed the particle flow—<strong>ParticleCore</strong>.</p><h4>The Particle Manager</h4><p><strong>ParticleCore</strong> is the class that manages internal particle sets, and is also the proxy for set activation, update, and rendering. Here is its structure:</p><p><pre class="brush: cpp">
#pragma once
#include &quot;pch.h&quot;
#include &quot;ParticleSet.h&quot;
#include &lt;list&gt;
#include &lt;map&gt;

class ParticleCore
{
    public:
    ParticleCore();
    ParticleCore(Coding4Fun::FallFury::Screens::GameScreenBase^);
    virtual ~ParticleCore();
    
    void CreatePreCachedParticleSets();
    void ActivateSet(Platform::String^, float2);
    void ActivateSet(Platform::String^, float2, float2);
    void ActivateSet(Platform::String^, float2, bool);
    void ActivateSet(Platform::String^, float2, float2, bool);
    void ActivateSet(Platform::String^, float2, float2, bool, bool scale);
    void Update(float);
    void Render();
    
    private:
        std::list&lt;ParticleSet&gt;                                                    _renderParticleSets;
        std::map&lt;Platform::String^, ParticleSet*&gt;                                _particleSetCache;
        std::map&lt;Platform::String^, Microsoft::WRL::ComPtr&lt;ID3D11Texture2D&gt;&gt;    _textureCache;
        Coding4Fun::FallFury::Screens::GameScreenBase^                            _screenBase;
};
</pre></p><p>As previously mentioned, set activation can be done with some omitted parameters inferred by the system, such as randomization of velocity or particle scaling, which is the reason why you see multiple overloads for <strong>ActivateSet</strong>.</p><p><strong>ParticleCore</strong> is also the container for pre-defined sets that have specific textures and properties that are dumped in the particle set cache (internal <strong>_particleSetCache</strong>). The cache is reusable and even though sets can be activated and destroyed, the cache remains intact for the duration of the game unless explicitly reset or modified. The texture cache is an addition to the particle set cache and is used as a helper container to temporarily store the textures used for individual particles.</p><p>Taking a look under the hood at the <strong>CreatePreCachedParticleSets</strong> function, you can see multiple sets that can be used in the game, each with different properties. Here is a snippet that shows how the bear stuffing explosion set is created:</p><p><pre class="brush: cpp">
auto smallExplosionSet = new ParticleSet(_textureCache[&quot;Stuffing&quot;], LIFESPAN);
for (int i = 0; i &lt; 20; i&#43;&#43;)
{
    float size = RandFloat(50.0f, 100.0f);
    Particle particle(float2(size, size));
    smallExplosionSet-&gt;AddParticle(particle);
}
</pre></p><p>&nbsp;</p><p>Once all the particles are in place for that specific set, it is added to the global particle set cache:</p><p><pre class="brush: cpp">
_particleSetCache[&quot;SmallExplosion&quot;] = smallExplosionSet;
</pre></p><p>The particle set cache is not explicitly used to render anything on the screen. Rather, that task is delegated to the rendering cache. When a set is activated, the cache is inspected for the given key, its Activate function is called, marking it as alive, and the set itself is pushed on the rendering stack:</p><p><pre class="brush: cpp">
void ParticleCore::ActivateSet(Platform::String^ name, float2 position, float2 velocity, bool randomize, bool scale)
{
    ParticleSet set = ParticleSet(*_particleSetCache[name]);
    set.Activate(position, velocity, randomize, scale);
    _renderParticleSets.push_back(set);
}
</pre></p><p>&nbsp;</p><p>The Render loop takes care of invoking the proper <strong>SpriteBatch</strong> drawing functions for each set that is in that stack:</p><p><pre class="brush: cpp">
void ParticleCore::Render()
{
    for (auto set = _renderParticleSets.begin(); set != _renderParticleSets.end(); &#43;&#43;set)
    {
        if ((*set).IsAlive())
        {
            (*set).Render(_screenBase-&gt;CurrentSpriteBatch);
        }
    }
}
</pre></p><p>&nbsp;</p><p>Notice that, as previously mentioned, the set does not perform the life check on itself when rendering. Instead, the manager class performs this action. The same applies to the <strong>Update</strong> loop:</p><p><pre class="brush: cpp">
void ParticleCore::Update(float timeDelta)
{
    for (auto set = _renderParticleSets.begin(); set != _renderParticleSets.end();)
    {
        if ((*set).IsAlive())
        {
            (*set).Update(timeDelta);
            &#43;&#43;set;
        }
        else
        {
            set = _renderParticleSets.erase(set);
        }
    }
}
</pre></p><p>&nbsp;</p><p>The textures for each set are individually loaded in the <strong>CreatePreCachedParticleSets</strong>. Each instance is internally pushed into the cache and also added to the sprite batch associated with the current game screen, where <strong>ParticleCore</strong> is used:</p><p><pre class="brush: cpp">
Loader-&gt;LoadTexture(&quot;DDS\\stuffing.dds&quot;, &amp;_textureCache[&quot;Stuffing&quot;], nullptr);
_screenBase-&gt;CurrentSpriteBatch-&gt;AddTexture(_textureCache[&quot;Stuffing&quot;].Get());
</pre></p><p>&nbsp;</p><p>Once everything is loaded, the <strong>ParticleCore</strong> is ready to go and you can use as many particles as necessary in any part of the application. In <strong>GamePlayScreen</strong>, particle sets are activated in many cases. For example, if the bear dies:</p><p><pre class="brush: cpp">
void GamePlayScreen::CheckBearHealth()
{
    if (GameBear-&gt;CurrentHealth &lt;= 0)
    {
        m_particleSystem.ActivateSet(&quot;Buttons&quot;,GameBear-&gt;Position, true);
        GameBear-&gt;Kill();
        StopBackground();
    }
}
</pre></p><p>&nbsp;</p><h4>Conclusion</h4><p>Implementing a sprite-based particle system is not complicated, but it requires depending on a number of assumptions. For example, when a particle set is created, you might consider the fact that some hardware can handle drawing only a given number of sprites at the same time. If a particle set is rendered on a desktop machine, there is no guarantee that the same set will successfully render on an ARM device. Therefore, plan accordingly. For each particle set, create a lifespan that fits the scenario without wasting resources on rendering unnecessary particles. As an additional failsafe, you might want to disable specific particle set types when a Direct3D feature level below 10.0 is detected.</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:d7f02957c420452a8791a14d01580aad">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-9-Particle-System</comments>
      <itunes:summary>Particle SystemDuring gameplay there are scenarios during which users need to be visually notified that something has happened, such as a collision with an obstacle or an enemy shell. One way to do this is by having explosion or item breaking simulation, which brings us to the next large component in FallFury—the sprite-based particle system. It doesn’t offer as much power as a full-fledged particle system would, but it allows for effects that fit well within the overall theme and layout of the game. Check out the video for this article at http://channel9.msdn.com/Series/FallFury/Part-9-Particle-System&amp;nbsp;.&amp;nbsp; For a complete, offline version of this series, you may download a nicely formatted PDF of all the articles. The CoreParticleSystem is the dedicated folder in the project that contains everything needed to render multiple textures at once and displace them to create the desired effect:  A single particle carries information regarding its size, position, velocity, color shading, rotation, circular velocity, and scale. As with any other rendered entity, it has a bounding box that can be used to detect its intersection with other elements on the screen. In FallFury, this functionality is not used. Its structure is as follows: 
#pragma once
#include &amp;quot;pch.h&amp;quot;
struct Particle
{
    Particle(float2 size);
    Particle(float2 size, float4 shading);
    float2 Size;
    float2 Position;
    float2 Velocity;
    float4 Shading;
    float Rotation;
    float RotationVelocity;
    float Scale;
    bool IsWithinScreenBoundaries(float x, float y, Windows::Foundation::Rect screenBounds);
    Windows::Foundation::Rect GetBoundingBox();
};
 The Particle class also happens to have two constructors—one that sets the particle to have the default shading, effectively removing the effect, and one where shading is dynamic. Note that a particle on its own doesn’t do much—it neither carries the associated texture nor has an internal loop that can be used</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-9-Particle-System</link>
      <pubDate>Wed, 23 Jan 2013 23:57:36 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-9-Particle-System</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/af7e/b408253b-7538-45b2-9b34-0685e059af7e/FallFuryPart9_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/af7e/b408253b-7538-45b2-9b34-0685e059af7e/FallFuryPart9_220.jpg" height="124" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/af7e/b408253b-7538-45b2-9b34-0685e059af7e/FallFuryPart9_512.jpg" height="289" width="512"></media:thumbnail>      
      <dc:creator>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</dc:creator>
      <itunes:author>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-9-Particle-System/RSS</wfw:commentRss>
      <category>C#</category>
      <category>C++</category>
      <category>DirectX</category>
      <category>Windows Store App</category>
    </item>
  <item>
      <title>Fall Fury: Part 8 - Element Interaction</title>
      <description><![CDATA[<h3>Element Interaction</h3><p>During the gameplay multiple entities interact with each other to make the gaming experience what it is. The bear collides with obstacles and collects buttons, monsters shoot shells that can fly off-screen or hit the bear—all this is possible with the help of the basic collision detection techniques that are implemented in FallFury.</p><p>Check out the video for this article at <a href="http://channel9.msdn.com/Series/FallFury/Part-8-Element-Interaction">http://channel9.msdn.com/Series/FallFury/Part-8-Element-Interaction</a>&nbsp;. For a complete, offline version of this series, you may <a href="http://media.ch9.ms/coding4fun/fallfury/FallFury.pdf">download a nicely formatted PDF of all the articles</a>.</p><h4>Buttons</h4><p>Buttons are bonus-boosters that can be placed by the level designer anywhere on the screen in game mode. These are relatively small entities, which are displaced vertically with each cycle of the <strong>Update</strong> loop and move in the opposite direction, but with the same velocity, as the main character.</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B2%5D-8.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb-9.png" alt="image" width="624" height="351" border="0"></a></p><p>Looking at the Update function in the GamePlayScreen class, you will notice this call:</p><p><pre class="brush: cpp">
UpdateButtons();
</pre></p><p><strong>UpdateButtons</strong> can be considered the button manager function responsible for removing the collected buttons from the rendering stack, counting them, and checking for a button collision when the bear is in close proximity. The implementation looks like this:</p><p><pre class="brush: cpp">
void GamePlayScreen::UpdateButtons()
{
    Windows::Foundation::Rect livingEntityBoundingBox = GameBear-&gt;GetBoundingBox();
    for (auto button = m_buttons.begin(); button != m_buttons.end();)
    {
        (*button)-&gt;Position.x = (*button)-&gt;PixelDiff &#43; LoBoundX;
        (*button)-&gt;Position.y -= GameBear-&gt;Velocity.y;
        if (Geometry::IsInProximity(GameBear-&gt;Position,(*button)-&gt;Position, 100))
        {
            Windows::Foundation::Rect obstacleRect = (*button)-&gt;GetBoundingBox();
            if (livingEntityBoundingBox.IntersectsWith(obstacleRect))
            {
                AudioManager::AudioEngineInstance.StopSoundEffect(Coin);
                AudioManager::AudioEngineInstance.PlaySoundEffect(Coin);
                m_particleSystem.ActivateSet(&quot;Sparkle&quot;, (*button)-&gt;Position,float2(RandFloat(-6.0f,6.0f),RandFloat(-10.0f, -5.0f)));
                StaticDataHelper::ButtonsCollected&#43;&#43;;
                button = m_buttons.erase(button);
            }
            else
            &#43;&#43;button;
        }
        else
        {
            &#43;&#43;button;
        }
    }
}
</pre></p><p>For performance reasons, FallFury supports composite bounding box creation as well as simple box creation. As mentioned earlier in the series, the main character is not composed of a single texture, but rather multiple sprites that are cross-positioned to create a single visual entity. To give you a better idea of what composite vs. simple boxing looks like, take a look at the images below:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B5%5D-10.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B1%5D-7.png" alt="image" width="266" height="225" border="0"></a><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B8%5D-4.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B2%5D-8.png" alt="image" width="226" height="222" border="0"></a></p><p>The image on the left shows how each part of the bear has its own bounding box, and each will be used for collision checking. In the image on the right, the bear has a single bounding box, creating minor potential gaps, but gaining performance.</p><p>Going back to <strong>UpdateButtons</strong>, once the bounding box is obtained, I iterate through the button collection and make sure that each item is located in the proper space:</p><p><pre class="brush: cpp">
(*button)-&gt;Position.x = (*button)-&gt;PixelDiff &#43; LoBoundX;
(*button)-&gt;Position.y -= GameBear-&gt;Velocity.y;
</pre></p><p>&nbsp;</p><p>The constant position checks are necessary because FallFury supports dynamic orientation changes. When the user switches from portrait to landscape mode and vice-versa, rendered elements on the screen are not automatically repositioned. Setting the X position is easy as long as there is a fixed button margin (from the left side of the screen: <strong>LoBoundX</strong>) and adding it to the current <strong>LoBoundX</strong> value results in a proper X location. There is no need to do the same check on the Y-axis because the level length remains the same regardless of the current screen orientation. The adjustment made relative the Y position is bound to the bear velocity. If the bear moves slower, buttons will also scroll slower.</p><p>Given that all buttons are properly positioned, a proximity check is performed on each button passed through the loop. If the bear position is at least 100 pixels away from the current button, the corresponding bounding box is obtained and an intersect check is performed. In simple boxing mode, this is done via <strong>Windows::Foundation::Rect::IntersectsWith</strong>:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B11%5D-4.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B3%5D-9.png" alt="image" width="562" height="61" border="0"></a></p><p>If a collision occurs, the appropriate sound effect is played and a particle set is activated to create a visual notification of the action. After the button counter is incremented, the button is removed from the local collection, effectively being removed from the rendering stack.</p><h4>Power-ups</h4><p>As the bear flies towards the end of the level, it might encounter bonuses to improve its ability to fight incoming enemies or protect from damage caused by enemy ammo or obstacles. The process behind displaying power-ups on the screen and determining whether there was a collision with the main character is similar to <strong>UpdateButtons</strong>.</p><p>The core function for this task is <strong>UpdatePowerups</strong>:</p><p><pre class="brush: cpp">
void GamePlayScreen::UpdatePowerups(float timeDelta)
{
    if (m_powerups.size() &gt; 0)
    {
        for (auto powerup = m_powerups.begin(); powerup != m_powerups.end(); powerup&#43;&#43;)
        {
            (*powerup)-&gt;Update(timeDelta);
            (*powerup)-&gt;Position.x = (*powerup)-&gt;PixelDiff &#43; LoBoundX;
            (*powerup)-&gt;Position.y -= GameBear-&gt;Velocity.y;
        }
    }
    CheckForCollisionWithPowerups();
}
</pre></p><p>&nbsp;</p><p>One difference you probably noticed in the snippet above is the fact that the collision check is now done through a separate function—<strong>CheckForCollisionWithPowerups</strong>:</p><p><pre class="brush: cpp">
void GamePlayScreen::CheckForCollisionWithPowerups()
{
    Powerup^ currentPowerup;
    Windows::Foundation::Rect livingEntityBoundingBox = GameBear-&gt;GetBoundingBox();
    for (auto powerup = m_powerups.begin(); powerup != m_powerups.end();)
    {
        currentPowerup = (*powerup);
        if (Geometry::IsInProximity(GameBear-&gt;Position,currentPowerup-&gt;Position, 100))
        {
            Windows::Foundation::Rect obstacleRect = currentPowerup-&gt;GetBoundingBox();
            if (livingEntityBoundingBox.IntersectsWith(obstacleRect))
            {
                AudioManager::AudioEngineInstance.PlaySoundEffect(GenericPowerup);
                GameBear-&gt;PickupPowerup(currentPowerup, &amp;m_particleSystem);
                powerup = m_powerups.erase(powerup);
            }
            else
            &#43;&#43;powerup;
        }
        else
        {
            &#43;&#43;powerup;
        }
    }
}
</pre></p><p>If an intersection is detected between the boxed bear and the power-up texture, the current power-up is passed to the <strong>Bear</strong> instance and the appropriate type of action is selected:</p><p><pre class="brush: cpp">
void Bear::PickupPowerup(Powerup^ powerup, ParticleCore* ParticleSystem)
{
    switch (powerup-&gt;Type)
    {
        case PowerupType::PARACHUTE:
        {
            m_previousVelocity = Velocity.y;
            SetParachute(powerup-&gt;Lifespan);
            Velocity.y -= powerup-&gt;Effect;
            ParticleSystem-&gt;ActivateSet(&quot;ScalableParachute&quot;, Position, 0.0f, false, true);
            break;
        }
        case PowerupType::HEALTH:
        {
            CurrentHealth = MaxHealth;
            ParticleSystem-&gt;ActivateSet(&quot;ScalableHeart&quot;, Position, 0.0f, false, true);
            break;
        }
        case PowerupType::BUBBLE:
        {
            if (IsHelmetEnabled)
            {
                IsHelmetEnabled = false;
                DamageDivider = 1.0f;
            }
            else
            {
                DamageDivider = powerup-&gt;Effect;
            }
            IsBubbleEnabled = true;
            m_maxBubbleCounter = powerup-&gt;Lifespan;
            ParticleSystem-&gt;ActivateSet(&quot;ScalableBubble&quot;, Position, 0.0f, false, true);
            break;
        }
        // [...]
        case PowerupType::BOOMERANG:
        {
            m_weaponType = powerup-&gt;Type;
            m_weaponTexture = m_boomerangTexture;
            CurrentDamage = powerup-&gt;Effect;
            m_weaponSize = float2(225.0f, 205.0f) * 0.5f;
            ParticleSystem-&gt;ActivateSet(&quot;ScalableBoomerang&quot;, Position, 0.0f, false, true);
            break;
        }
    }
}
</pre></p><p>Depending on the power-up, textures are added to the bear model and later passed to the rendering stack (if the power-up type is <strong>PARACHUTE</strong>), some textures and capabilities are replaced (<strong>BOOMERANG</strong>), or the bear capabilities are temporarily modified (<strong>BUBBLE</strong>):</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B14%5D-4.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B4%5D-3.png" alt="image" width="359" height="358" border="0"></a></p><p>If one of the temporary power-ups is enabled n the <strong>Update</strong> loop, dedicated timers ensure that ability enhancement does not last longer than necessary. As an example, here is the snippet that controls the bubble:</p><p><pre class="brush: cpp">
if (IsBubbleEnabled)
{
    m_currentBubbleCounter &#43;= timeDelta;
    if (m_currentBubbleCounter &gt; m_maxBubbleCounter)
    {
        IsBubbleEnabled = false;
        DamageDivider = 1.0f;
        m_currentBubbleCounter = 0.0f;
    }
}
</pre></p><p>&nbsp;</p><h4>Ammo Collisions</h4><p>There are also objects that direct ammo at either the enemy or the bear. After release, each shell follows a linear path towards the target, and while the user directs the shells that originate from the bear, those released by enemy entities automatically target the bear. In this case, the ammo needs to collide with an object to either damage or kill it. When a shell is released, it is added to the general ammo collection that is later updated internally:</p><p><pre class="brush: cpp">
void GamePlayScreen::UpdateAmmo(float timeDelta)
{
    for (auto shell = m_ammoCollection.begin(); shell != m_ammoCollection.end(); shell&#43;&#43;)
    {
        (*shell)-&gt;Update(timeDelta, &amp;m_particleSystem);
    }
}
</pre></p><p>&nbsp;</p><p>At this point, the rendering system does not differentiate between friendly and enemy ammo—all it knows is that each item in the collection must have a new position when a new frame is rendered. The <strong>CheckForCollisionsWithAmmo</strong> function checks for ammo collisions:</p><p><pre class="brush: cpp">
void GamePlayScreen::CheckForCollisionWithAmmo(LivingEntity^ entity)
{
    if (entity != nullptr)
    {
        Windows::Foundation::Rect livingEntityBoundingBox = entity-&gt;GetBoundingBox();
        if (entity-&gt;IsFriendly)
        {
            for (auto ammo = m_ammoCollection.begin(); ammo != m_ammoCollection.end();)
            {
                if (!(*ammo)-&gt;IsFriendly)
                {
                    Windows::Foundation::Rect ammoBoundingBox = (*ammo)-&gt;GetBoundingBox();
                    if (livingEntityBoundingBox.IntersectsWith(ammoBoundingBox))
                    {
                        m_particleSystem.ActivateSet(&quot;SmallExplosion&quot;,entity-&gt;Position, true);
                        entity-&gt;InflictDamage((*ammo)-&gt;HealthDamage);
                        GameBear-&gt;RedShade();
                        AudioManager::AudioEngineInstance.PlaySoundEffect(OuchA);
                        AudioManager::AudioEngineInstance.PlaySoundEffect(HardSoftCollision);
                        CheckBearHealth();
                        ammo = m_ammoCollection.erase(ammo);
                    }
                    else
                    {
                        &#43;&#43;ammo;
                    }
                }
                else
                {
                    &#43;&#43;ammo;
                }
            }
        }
        else
        {
            for (auto ammo = m_ammoCollection.begin(); ammo != m_ammoCollection.end();)
            {
                if ((*ammo)-&gt;IsFriendly)
                {
                    Windows::Foundation::Rect ammoBoundingBox = (*ammo)-&gt;GetBoundingBox();
                    if (livingEntityBoundingBox.IntersectsWith(ammoBoundingBox))
                    { 
                        Monster^ monster = ((Monster^)entity);
                        if (!monster-&gt;IsDead &amp;&amp; monster-&gt;IsActive)
                        {
                            m_particleSystem.ActivateSet(&quot;SmallExplosion&quot;, entity-&gt;Position, true);
                            entity-&gt;InflictDamage((*ammo)-&gt;HealthDamage);
                            monster-&gt;RedShade();
                            monster-&gt;CheckIfAlive();
                            AudioManager::AudioEngineInstance.PlaySoundEffect(SharpSoftCollision);
                        }
                        ammo = m_ammoCollection.erase(ammo);
                    }
                    else
                    {
                        &#43;&#43;ammo;
                    }
                }
                else
                {
                    &#43;&#43;ammo;
                }
            }
        }
    }
}
</pre></p><p>When the function is called, it is usually run against an entity that is present on the screen, such as the main character. Regardless of whether the enemy or the friendly character fired the shot, the shot cannot inflict damage to its source, and that’s why the function implements the ammo-to-entity crosscheck. If the ammo collides with any shells intersecting the entity bounding box, a collision is counted and health verification is performed to ensure that the character is still alive and that the game should continue. The bear’s health is checked via <strong>CheckBarHealth</strong>:</p><p><pre class="brush: cpp">
void GamePlayScreen::CheckBearHealth()
{
    if (GameBear-&gt;CurrentHealth &lt;= 0)
    {
        m_particleSystem.ActivateSet(&quot;Buttons&quot;,GameBear-&gt;Position, true);
        GameBear-&gt;Kill();
        StopBackground();
    }
}
</pre></p><p>That said, not all ammo will collide with entities on the screen. Some of it will go out-of-bounds, and without an explicit cleanup process in place out-of-bounds ammo is constantly re-rendered even though the end user has no way of seeing it. To avoid this, there is a helper function—<strong>CheckForOutOfBoundsAmmo</strong>:</p><p><pre class="brush: cpp">
void GamePlayScreen::CheckForOutOfBoundsAmmo()
{
    for (auto l_Iter = m_ammoCollection.begin(); l_Iter != m_ammoCollection.end(); /* nothing here */ )
    {
        if (!GamePlayScreen::Manager-&gt;IsWithinScreenBoundaries((*l_Iter)-&gt;Position))
        {
            l_Iter = m_ammoCollection.erase(l_Iter);
        }
        else
        {
            &#43;&#43;l_Iter;
        }
    }
}
</pre></p><p>If any shell flies outside the screen bounding box, its instance is erased from the collection and the renderer no longer worries about allocating memory for an irrelevant item. To give you an idea of how that happens, here is a snippet that shows how the <strong>RenderScreen</strong> function handles the current ammo set:</p><p><pre class="brush: cpp">
if (!m_ammoCollection.empty())
{
    for (auto shell = m_ammoCollection.begin(); shell != m_ammoCollection.end(); shell&#43;&#43;)
    {
        if (!(*shell)-&gt;IsFriendly)
        {
            (*shell)-&gt;Render();
        }
        else
        {
            GameBear-&gt;RenderShell((*shell)-&gt;Position, (*shell)-&gt;Rotation);
        }
    }
}
</pre></p><p>&nbsp;</p><h4>Conclusion</h4><p>Element interaction is a core part of the FallFury experience. Separate handlers are implemented for each of them to ensure maximum flexibility when it comes to adding or removing components without breaking major parts of the code-base. Handling is mainly accomplished in the Update loop by iterating through registered entity sets, such as ammo, and verifying whether an action should be taken. Be cautious when implementing this kind of scenario with large entities and data sets—having multiple loops running simultaneously might tax machine performance, especially on low-power configurations such as ARM.</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:79ffea1b09074fc7bfd9a14d01549989">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-8-Element-Interaction</comments>
      <itunes:summary>Element InteractionDuring the gameplay multiple entities interact with each other to make the gaming experience what it is. The bear collides with obstacles and collects buttons, monsters shoot shells that can fly off-screen or hit the bear—all this is possible with the help of the basic collision detection techniques that are implemented in FallFury. Check out the video for this article at http://channel9.msdn.com/Series/FallFury/Part-8-Element-Interaction&amp;nbsp;. For a complete, offline version of this series, you may download a nicely formatted PDF of all the articles. ButtonsButtons are bonus-boosters that can be placed by the level designer anywhere on the screen in game mode. These are relatively small entities, which are displaced vertically with each cycle of the Update loop and move in the opposite direction, but with the same velocity, as the main character.  Looking at the Update function in the GamePlayScreen class, you will notice this call: 
UpdateButtons();
 UpdateButtons can be considered the button manager function responsible for removing the collected buttons from the rendering stack, counting them, and checking for a button collision when the bear is in close proximity. The implementation looks like this: 
void GamePlayScreen::UpdateButtons()
{
    Windows::Foundation::Rect livingEntityBoundingBox = GameBear-&amp;gt;GetBoundingBox();
    for (auto button = m_buttons.begin(); button != m_buttons.end();)
    {
        (*button)-&amp;gt;Position.x = (*button)-&amp;gt;PixelDiff &amp;#43; LoBoundX;
        (*button)-&amp;gt;Position.y -= GameBear-&amp;gt;Velocity.y;
        if (Geometry::IsInProximity(GameBear-&amp;gt;Position,(*button)-&amp;gt;Position, 100))
        {
            Windows::Foundation::Rect obstacleRect = (*button)-&amp;gt;GetBoundingBox();
            if (livingEntityBoundingBox.IntersectsWith(obstacleRect))
            {
                AudioManager::AudioEngineInstance.StopSoundEffect(Coin);
                AudioManager::AudioEngineInstance.PlaySoundEf</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-8-Element-Interaction</link>
      <pubDate>Wed, 23 Jan 2013 23:57:25 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-8-Element-Interaction</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/3d85/e97b9237-10bd-414e-b825-986d050e3d85/FallFuryPart8_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/3d85/e97b9237-10bd-414e-b825-986d050e3d85/FallFuryPart8_220.jpg" height="124" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/3d85/e97b9237-10bd-414e-b825-986d050e3d85/FallFuryPart8_512.jpg" height="289" width="512"></media:thumbnail>      
      <dc:creator>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</dc:creator>
      <itunes:author>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-8-Element-Interaction/RSS</wfw:commentRss>
      <category>C#</category>
      <category>C++</category>
      <category>DirectX</category>
      <category>Windows Store App</category>
    </item>
  <item>
      <title>Fall Fury: Part 7 - Animations</title>
      <description><![CDATA[<h3>Animations &amp; Item Transitions</h3><p>FallFury relies on a lot of dynamic content. As you already aware of how <strong>SpriteBatch</strong> is invoked inside the FallFury rendering stack, this article focuses on how dynamic activities are handled on existing textures and entities. If you need a quick look at what was already covered, refer to Part 3 of the series.</p><p>Check out the video for this article at <a href="http://channel9.msdn.com/Series/FallFury/Part-7-Animations">http://channel9.msdn.com/Series/FallFury/Part-7-Animations</a>&nbsp;. For a complete, offline version of this series, you may <a href="http://media.ch9.ms/coding4fun/fallfury/FallFury.pdf">download a nicely formatted PDF of all the articles</a>.</p><h3>Menu Screen</h3><p>The first animated element shown in the menu screen is the bear, which is positioned in the top half of the viewport. Notice that the bear moves its paws as well as moving across the screen:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B2%5D-7.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb-8.png" alt="image" width="624" height="351" border="0"></a></p><p>The bear is implemented in the <strong>GameBear</strong> class and is the normal playable entity that is invincible when animated outside the scope of the gameplay screen. Its full body image is composed of four textures:</p><p><pre class="brush: cpp">
Microsoft::WRL::ComPtr&lt;ID3D11Texture2D&gt;        m_head;
Microsoft::WRL::ComPtr&lt;ID3D11Texture2D&gt;        m_leftPaw;
Microsoft::WRL::ComPtr&lt;ID3D11Texture2D&gt;        m_rightPaw;

Microsoft::WRL::ComPtr&lt;ID3D11Texture2D&gt;        m_body // Exposed through LivingEntity;
</pre></p><p>Each of these textures is internally dependent on the coupled float rotation and position values passed to the sprite batch in the host container (the parent screen):</p><p><pre class="brush: cpp">
HostContainer-&gt;CurrentSpriteBatch-&gt;Draw(
    m_rightPaw.Get(),
    m_rightPawPosition,
    PositionUnits::DIPs,
    float2(522.0f, 141.0f) * Scale,
    SizeUnits::Pixels,
    m_shading,
    m_rightPawRotation - 0.5f);

HostContainer-&gt;CurrentSpriteBatch-&gt;Draw(
    m_body.Get(),
    Position,
    PositionUnits::DIPs,
    float2(400.0f, 400.0f) * Scale,
    SizeUnits::Pixels,
    m_shading,
    Rotation);

HostContainer-&gt;CurrentSpriteBatch-&gt;Draw(
    m_leftPaw.Get(),
    m_leftPawPosition,
    PositionUnits::DIPs,
    float2(522.0f, 141.0f) * Scale,
    SizeUnits::Pixels,
    m_shading,
    m_leftPawRotation &#43; 0.5f);
</pre></p><p>Let’s take a look at how the position and rotation values are modified. All item animations are performed with the help of timers set to brief intervals in which the values are cycled through two value exchange operations. Here is a snippet taken from inside the Update method in the <strong>GameBear</strong> class that is responsible for bear arm movement:</p><p><pre class="brush: cpp">
if (m_armRotationTimer &lt; 0.6f)
{
    m_rightPawRotation -= 0.005f;
    m_leftPawRotation &#43;= 0.005f;
}
else if (m_armRotationTimer &gt; 0.6f &amp;&amp; m_armRotationTimer &lt; 1.2f)
{
    m_rightPawRotation &#43;= 0.005f;
    m_leftPawRotation -= 0.005f;
}
else
{
    m_rightPawRotation = 0.0f;
    m_leftPawRotation = 0.0f;
    m_armRotationTimer = 0.0f;
}
</pre></p><p><strong>m_armRotationTimer</strong> is a float value that is initially set to <strong>0.0f</strong>. In the <strong>Update</strong> loop and increments each iteration by the value of <strong>timeDelta</strong>, which represents the time difference between two loop cycles. As this value is less than 600 milliseconds (0.6 seconds), the right paw rotation is incremented and the left paw rotation decremented. The difference in the value adjustment direction is caused by the fact that one paw is rotated clockwise and the other is rotated counterclockwise. Once the timer tracks a value above 600 milliseconds but below than 1200 milliseconds, the process reverses and the paws rotate in the opposite direction. After 1.2 seconds, the timer resets, as does the rotation.</p><p>Since this rotation is automated, <strong>GameBear-&gt;Update</strong> is called in the menu screen:</p><p><pre class="brush: cpp">
m_showBear-&gt;Update(timeTotal, timeDelta, float2(Manager-&gt;m_windowBounds.Width / 2, Manager-&gt;m_windowBounds.Height / 2));
</pre></p><p>Outside the context of the bear update cycle, there is a similar timed mechanism used to randomly move the bear across the screen:</p><p><pre class="brush: cpp">
if (m_positionYAdj == 0.0f)
{
    m_positionYAdj = RandFloat(0.1f, 1.2f);
    m_positionXAdj = RandFloat(-1.0f, 1.0f);
}

if (m_positionTimer &lt; 4.0f)
{
    m_showBear-&gt;Position.x &#43;= m_positionXAdj;
    m_showBear-&gt;Position.y &#43;= m_positionYAdj;
    m_showBear-&gt;Rotation &#43;= 0.001f;
    m_showBear-&gt;Scale &#43;= 0.0008f;
    
    m_showMonster-&gt;Scale &#43;= 0.002f;
}
else if (m_positionTimer &gt; 4.0f &amp;&amp; m_positionTimer &lt; 8.0f)
{
    m_showBear-&gt;Position.x -= m_positionXAdj;
    m_showBear-&gt;Position.y -= m_positionYAdj;
    m_showBear-&gt;Rotation -= 0.001f;
    m_showBear-&gt;Scale -= 0.0008f;
}
else
{
    m_positionYAdj = 0.0f;
    m_positionTimer = 0.0f;
}
</pre></p><p>The X and Y adjustments are randomly generated and for the duration of a single timer cycle (in this case, 4 seconds) the bear’s horizontal and vertical positions are adjusted using those values. The rotation and scale are minimally adjusted to create a 3D motion effect. Because the displacement is minimal, the bear is always visible and does not move much outside the viewport.</p><p>There is also a flying monster animation in the main menu screen. Monster creation happens on top of the same instance that is replaced when an initial monster flies out of bounds:</p><p><pre class="brush: cpp">
m_showMonster-&gt;Position.y -= m_showMonster-&gt;Velocity.y;
if (m_showMonster-&gt;Position.y &lt; -m_showMonster-&gt;Size.y)
{
    CreateNewMonster();
}
</pre></p><p>&nbsp;</p><p>When a new monster is created, a random monster type is selected and its position on the X axis is randomized. The Y position is set to be right under the bottom screen boundary:</p><p><pre class="brush: cpp">
void MenuScreen::CreateNewMonster()
{
    m_showMonster = ref new Monster(this, (MonsterType)(rand() % (int)MonsterType::MT_CANDYLAND_E), true);
    m_showMonster-&gt;Scale = 0.3f;
    m_showMonster-&gt;Velocity.y = 1.0f;
    m_showMonster-&gt;Load();
    m_showMonster-&gt;Position = float2(RandFloat(LoBoundX, HiBoundX), Manager-&gt;m_windowBounds.Height &#43; m_showMonster-&gt;Size.y * m_showMonster-&gt;Scale);
}
</pre></p><p>Monster scaling is done on the same timed loop as the bear. The results look like this:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B5%5D-9.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B1%5D-6.png" alt="image" width="640" height="362" border="0"></a></p><h3>Gameplay Screen</h3><h4>Bear</h4><p>The gameplay screen carries the most animations in FallFury, including animations related to ammo displacement, monster movement paths, power-up animations, and secondary game character animations that are triggered in special cases such as character death.</p><p>Let’s start with character entrance. When the game begins, the teddy bear falls into the screen and stops at a specific point close to the top boundary of the gameplay screen. Once that transition is complete, the bear is no longer vertically displaced:</p><p><pre class="brush: cpp">
if ((GameBear-&gt;Position.y / HiBoundY) &lt; 0.19f)
{
    GameBear-&gt;Position.y &#43;= GameBear-&gt;Velocity.y * (3.2f);
}
</pre></p><p>&nbsp;</p><p>If the limit is not hit, the original bear velocity is multiplied by a fixed value, after which the condition is ignored for the rest of the gameplay.</p><p>Let’s now take a look at what happens when an enemy shell kills the bear. Generally, when the main character is killed, there is not much sense in maintaining other in-game activities. In FallFury, a killed bear results in a time freeze—the fall stops and the monsters are no longer shooting or moving. Not only that, but the bear is also flipped on its back:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B11%5D-3.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B3%5D-8.png" alt="image" width="386" height="387" border="0"></a></p><p>In the <strong>Update</strong> loop, the position for the paws and the head are adjusted for the new body texture layout:</p><p><pre class="brush: cpp">
if (IsDead)
{
    if (m_armRotationTimer &lt; 1.0f)
    {
        m_rightPawRotation &#43;= 0.001f;
        m_leftPawRotation -= 0.001f;
    }
    else if (m_armRotationTimer &gt; 1.0f &amp;&amp; m_armRotationTimer &lt; 2.0f)
    {
        m_rightPawRotation -= 0.001f;
        m_leftPawRotation &#43;= 0.001f;
    }
    else
    {
        m_rightPawRotation = 0.0f;
        m_leftPawRotation = 0.0f;
        m_armRotationTimer = 0.0f;
    }

    m_rightPawPosition = Position &#43; float2(40.0f, -50.0f) * Scale;
    m_leftPawPosition = Position &#43; float2(10.0f, 150.0f) * Scale;
    m_headPosition = (Position - float2(-160.0f, 0.0f) * Scale);
}
</pre></p><p>The proper textures are assigned via the <strong>Kill</strong> method:</p><p><pre class="brush: cpp">
void Bear::Kill()
{
    IsDead = true;
    Rotation = -1.0f;
    m_head = m_deadHead;
    m_body = m_deadBody;
    m_leftPaw = m_deadLeftArm;
    m_rightPaw = m_deadRightArm;
}
</pre></p><p>The bear will continue falling as long as <strong>StopBackground</strong> in <strong>GamePlayScreen</strong> is called:</p><p><pre class="brush: cpp">
void GamePlayScreen::StopBackground()
{
    m_isBackgroundMoving = false;
}
</pre></p><p>This will cause the internal state check to fail in the <strong>Update</strong> loop, sending the bear off screen limits. Once the bear completes the fall, the state is set to <strong>GS_GAME_OVER</strong>:</p><p><pre class="brush: cpp">
if (!m_isBackgroundMoving)
{
    if (GameBear-&gt;Position.y &gt; m_screenSize.y)
    {
        Manager-&gt;CurrentGameState = GameState::GS_GAME_OVER;
    }
    else
    {
        GameBear-&gt;Position.y &#43;= GameBear-&gt;Velocity.y * 1.5f;
    }
}
</pre></p><h4>Monsters</h4><p>Monsters, on the other hand, are being constantly moved during the duration of the game. Their basic displacement is performed by MoveMonsters:</p><p><pre class="brush: cpp">
void GamePlayScreen::MoveMonsters(float timeTotal ,float timeDelta)
{
    for (auto monster = m_monsters.begin(); monster != m_monsters.end();)
    {
        Monster^ currentMonster = (*monster);
        if ((currentMonster-&gt;Position.y - GameBear-&gt;Position.y) &lt; -Manager-&gt;m_renderTargetSize.Height / 2)
        {
            monster = m_monsters.erase(monster);
        }
        else
        {
            currentMonster-&gt;Velocity.y = GameBear-&gt;Velocity.y;
            currentMonster-&gt;Update(timeTotal, timeDelta, GameBear-&gt;Position, GetScreenBounds());
            CheckForCollisionWithAmmo(currentMonster);
            &#43;&#43;monster;
        }
    }
}
</pre></p><p>This method adjusts the monster position relative to the bear:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B14%5D-3.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B4%5D-2.png" alt="image" width="622" height="349" border="0"></a></p><p>The zig-zag like motion is defined in the <strong>Monster</strong> class in the <strong>Update</strong> method:</p><p><pre class="brush: cpp">
float adjustment = 0.0f;
adjustment = m_goingRight ? Position.x &#43; Velocity.x : Position.x - Velocity.x;
if (adjustment &gt;= (HostContainer-&gt;LoBoundX &#43; (Size.x * Scale) / 2.0f) 
&amp;&amp; adjustment &lt;= (HostContainer-&gt;HiBoundX - (Size.x * Scale) / 2.0f))
{
    Position.x = adjustment;
}
else
{
    m_goingRight = !m_goingRight;
}
</pre></p><p>&nbsp;</p><p>The snippet above determines the direction in which the enemy has to move depending on which screen boundary is hit first. While the monster is active and is visible, its vertical adjustment is performed in a timed loop, like this:</p><p><pre class="brush: cpp">
m_jumpingTimer &#43;= timeDelta;
if (m_jumpingTimer &gt; 0.0f &amp;&amp; m_jumpingTimer &lt; 1.0f)
{
    Position.y -= 1.0f;
}
else if (m_jumpingTimer &gt;= 1.0f &amp;&amp; m_jumpingTimer &lt; 2.0f)
{
    Position.y &#43;= 1.0f;
}
else
{
    m_jumpingTimer = 0.0f;
}
</pre></p><p>Here you can either use the Y velocity or introduce a static value. The only condition has to be a number low enough that the monster does not leave the screen, which would prevent the bear from being able to kill it. When the monster is killed, it flies out by following an arch-like path:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B17%5D-1.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B5%5D-1.png" alt="image" width="487" height="480" border="0"></a></p><p>The “death arc” is implemented via another timer:</p><p><pre class="brush: cpp">
Position.x &#43;= Velocity.y * 1.3f;
if (m_deathArcTimer &gt; 0.4f)
{
    Position.y &#43;= Velocity.y;
    if (Scale &gt; 0.1f)
    Scale -= 0.01f;
}
else
{
    Position.y -= Velocity.y;
    Scale &#43;= 0.01f;
    m_deathArcTimer &#43;= timeDelta;
}
</pre></p><p>&nbsp;</p><p>Regardless of the monster position, the horizontal displacement is positive and the entity moves to the right. For 400 milliseconds its vertical position is decreased, moving the texture up, and the scale is also adjusted to create the proximity effect. After this time interval, the monster drops out of the screen boundaries.</p><p>As previously mentioned, each monster is composed of three cycled textures, which are loaded and stored in three ID3D11Texture2D containers:</p><p><pre class="brush: cpp">
Microsoft::WRL::ComPtr&lt;ID3D11Texture2D&gt; m_spriteA;
Microsoft::WRL::ComPtr&lt;ID3D11Texture2D&gt; m_spriteB;
Microsoft::WRL::ComPtr&lt;ID3D11Texture2D&gt; m_spriteC;
</pre></p><p>&nbsp;</p><p>Each of these is assigned to the main body texture container every 300 milliseconds, replacing the previously assigned asset:</p><p><pre class="brush: cpp">
m_stateChangeTimer &#43;= timeDelta;
if (m_stateChangeTimer &lt; 0.3f)
{
    m_body = m_spriteA;
}
else if (m_stateChangeTimer &gt; 0.3f &amp;&amp; m_stateChangeTimer &lt; 0.6f)
{
    m_body = m_spriteB;
}
else if (m_stateChangeTimer &gt; 0.6f &amp;&amp; m_stateChangeTimer &lt; 0.9f)
{
    m_body = m_spriteC;
}
else if (m_stateChangeTimer &gt; 0.9f)
{
    m_stateChangeTimer = 0.0f;
}
</pre></p><p>&nbsp;</p><p>This cycle can be disabled when the monster is not active.</p><h4>Ammo</h4><p>There are different types of ammo used in the game, and each behaves in its own way. The stock ammo type is a plasma ball.</p><p>The default shooting behavior releases a shell when the user taps anywhere on the screen (other than the pause button area). Given the texture of the shell, when it is released the tail must be oriented towards the bear at an angle equal to the one created by the bear and the target position. To get a better idea, take a look at the images below:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B20%5D-4.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B6%5D-5.png" alt="image" width="339" height="340" border="0"></a><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B23%5D-1.png">&nbsp;<img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B7%5D-3.png" alt="image" width="340" height="340" border="0"></a></p><p>In the image on the left, the player tapped at the bottom of the screen. In the one on the right, the player tapped at the right edge of the screen. The shell accordingly rotates depending on the tapped position. To get a better understanding of how the rotation is performed, imagine the XY coordinate grid with the bear located at the intersection of the axes:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B26%5D-2.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B8%5D-7.png" alt="image" width="622" height="279" border="0"></a></p><p>Thinking back to trigonometry, notice the triangle formed by the shell and the bear origin point:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B29%5D-3.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B9%5D-2.png" alt="image" width="288" height="182" border="0"></a></p><p>Remember also the trig concept of quadrants:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B32%5D-1.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B10%5D-5.png" alt="image" width="623" height="278" border="0"></a></p><p>The quadrant in which the shell is located determines how the angle is calculated and the tail rotated. If the shell is in quadrant 2 or 3, calculate the rotation radians by following this algorithm:</p><p>1. Find the hypotenuse from the X and Y components of the velocity, which can be calculated by finding the difference between the bear and the position of the tap. To do this, us the well-known Pythagorean theorem:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B35%5D-1.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B11%5D-2.png" alt="image" width="100" height="20" border="0"></a></p><p>The hypotenuse formula can be deduced from the formula above and is the square root of the sum of the velocity component squares:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B38%5D-1.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B12%5D-5.png" alt="image" width="114" height="21" border="0"></a></p><p>2. Once calculated, it is necessary to find the sine of the target angle. The value can be obtained by dividing the Y component of the velocity by the hypotenuse.</p><p>3. Find the angle by calculating the arcsine from the resultant sine value. This will return the final angle in radians.</p><p>That said, for shells launched in quadrants 1 or 4, there is one extra step that needs to be performed. In addition to the rotation value obtained from the steps listed above, the rotation should be incremented by the radian value of a 180-degree angle minus twice the rotation value previously obtained. This ensures that the tail is correctly flipped relative to the axis origin.</p><p>In C&#43;&#43;, the implementation is done inside the <strong>AmmoItem</strong> class. For flexibility purposes, it triggers inside the <strong>Update</strong> loop—that way, it is possible to modify the trajectory of the shell and not worry about turning it again manually after launch:</p><p><pre class="brush: cpp">
if ((Velocity.x &gt; 0 &amp;&amp; Velocity.y &gt; 0) || (Velocity.x &gt; 0 &amp;&amp; Velocity.y &lt;0))
{
    Rotation = CalculateRadians(Velocity);
    Rotation &#43;= CalculateRadiansFromAngle(180) - 2 * Rotation;
}
else
{
    Rotation = CalculateRadians(Velocity);
}
</pre></p><p><strong>CalculateRadians</strong> is the method that transforms the velocity components in a rotation value. It is located in the <strong>BasicMath.h </strong>helper:</p><p><pre class="brush: cpp">
inline float CalculateRadians(float2 velocity)
{
    float hypothenuse = sqrt(velocity.x * velocity.x &#43; velocity.y * velocity.y);
    float sine = velocity.y / hypothenuse;
    float angle = asin(sine);
    return angle;
};
</pre></p><p>&nbsp;</p><p>There is a potential problem with the implementation above. As the user taps on different parts of the screen, the X and Y components are different, each resulting in a different hypotenuse. As the target is set, the shell flies faster the further away from the bear the user taps. To avoid this, the triangle legs should be normalized to a near-constant value:</p><p>Take a look at the <strong>ShootAtTarget</strong> function in the Bear class:</p><p><pre class="brush: cpp">
void Bear::ShootAtTarget(float2 lastTargetTrace)
{
    OnPulledTrigger(Position.x, Position.y, 
    GetVelocityLegs(lastTargetTrace).x, GetVelocityLegs(lastTargetTrace).y, 
    CurrentDamage, IsFriendly, false, HostContainer-&gt;CurrentSpriteBatch);
}
</pre></p><p>&nbsp;</p><p>Notice that the triangle legs are not passed as a raw value, but are proxied through <strong>GetVelocityLegs</strong>, which forces the resulting vector to be produced from a constant triangle with the velocity constant at 10 pixels per iteration:</p><p><pre class="brush: cpp">
float2 LivingEntity::GetVelocityLegs(float2 lastTargetTrace)
{
    float bottomLeg = 0.0f;
    float sideLeg = (Position.y - lastTargetTrace.y) / 100.0f;
    bottomLeg = (Position.x - lastTargetTrace.x) / 100.0f;
    float requiredVelocity = 10.0f;
    float hypothenuse = sqrt(bottomLeg * bottomLeg &#43; sideLeg * sideLeg);
    float proportionalX = 0.0f;
    float proportionalY = 0.0f;
    proportionalX = (requiredVelocity * bottomLeg) / hypothenuse;
    proportionalY = (sideLeg &lt; 0.0f ? -1 : 1) * sqrt(requiredVelocity * requiredVelocity - proportionalX * proportionalX);
    return float2(proportionalX,proportionalY);
}
</pre></p><p>&nbsp;</p><p>For ammo that does not have a visual rotation dependency, such as the plasma ball, simply increment the rotation to make the thrown item continuously spin:</p><p><pre class="brush: cpp">
if (Type == PowerupType::PLASMA_BALL)
{
    if ((Velocity.x &gt; 0 &amp;&amp; Velocity.y &gt; 0) || (Velocity.x &gt; 0 &amp;&amp; Velocity.y &lt;0))
    {
        Rotation = CalculateRadians(Velocity);
        Rotation &#43;= CalculateRadiansFromAngle(180) - 2 * Rotation;
    }
    else
    {
        Rotation = CalculateRadians(Velocity);
    }
}
else
{
    Rotation &#43;= 0.2f;
}
</pre></p><p>&nbsp;</p><h3>Conclusions</h3><p>FallFury mostly relies on sprite-based animations in which there are several textures cycled through in order to create the desired dynamic effect. These are not really hard to build, given that there is a possibility to integrate them in a timed loop. Be aware, however, that with slower machines the timing might be off and the time delta value between loops might be higher. In that case the sprite cycling will not be as smooth as it should be, which is why it’s important to perform animation testing on a variety of hardware with different OS loads.</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:cf9dec8e099f4f63a437a14d0152aeab">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-7-Animations</comments>
      <itunes:summary>Animations &amp;amp; Item TransitionsFallFury relies on a lot of dynamic content. As you already aware of how SpriteBatch is invoked inside the FallFury rendering stack, this article focuses on how dynamic activities are handled on existing textures and entities. If you need a quick look at what was already covered, refer to Part 3 of the series. Check out the video for this article at http://channel9.msdn.com/Series/FallFury/Part-7-Animations&amp;nbsp;. For a complete, offline version of this series, you may download a nicely formatted PDF of all the articles. Menu ScreenThe first animated element shown in the menu screen is the bear, which is positioned in the top half of the viewport. Notice that the bear moves its paws as well as moving across the screen:  The bear is implemented in the GameBear class and is the normal playable entity that is invincible when animated outside the scope of the gameplay screen. Its full body image is composed of four textures: 
Microsoft::WRL::ComPtr&amp;lt;ID3D11Texture2D&amp;gt;        m_head;
Microsoft::WRL::ComPtr&amp;lt;ID3D11Texture2D&amp;gt;        m_leftPaw;
Microsoft::WRL::ComPtr&amp;lt;ID3D11Texture2D&amp;gt;        m_rightPaw;

Microsoft::WRL::ComPtr&amp;lt;ID3D11Texture2D&amp;gt;        m_body // Exposed through LivingEntity;
 Each of these textures is internally dependent on the coupled float rotation and position values passed to the sprite batch in the host container (the parent screen): 
HostContainer-&amp;gt;CurrentSpriteBatch-&amp;gt;Draw(
    m_rightPaw.Get(),
    m_rightPawPosition,
    PositionUnits::DIPs,
    float2(522.0f, 141.0f) * Scale,
    SizeUnits::Pixels,
    m_shading,
    m_rightPawRotation - 0.5f);

HostContainer-&amp;gt;CurrentSpriteBatch-&amp;gt;Draw(
    m_body.Get(),
    Position,
    PositionUnits::DIPs,
    float2(400.0f, 400.0f) * Scale,
    SizeUnits::Pixels,
    m_shading,
    Rotation);

HostContainer-&amp;gt;CurrentSpriteBatch-&amp;gt;Draw(
    m_leftPaw.Get(),
    m_leftPawPosition,
    PositionUnits::DIPs,
    float2(522</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-7-Animations</link>
      <pubDate>Wed, 23 Jan 2013 23:57:22 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-7-Animations</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/5a90/d869aabf-608a-42a9-b8b5-3512c3e65a90/FallFuryPart7_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/5a90/d869aabf-608a-42a9-b8b5-3512c3e65a90/FallFuryPart7_220.jpg" height="124" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/5a90/d869aabf-608a-42a9-b8b5-3512c3e65a90/FallFuryPart7_512.jpg" height="289" width="512"></media:thumbnail>      
      <dc:creator>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</dc:creator>
      <itunes:author>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-7-Animations/RSS</wfw:commentRss>
      <category>C#</category>
      <category>C++</category>
      <category>DirectX</category>
      <category>Windows Store App</category>
    </item>
  <item>
      <title>Fall Fury: Part 6 - Rendering Level Elements</title>
      <description><![CDATA[<h4>Rendering Level Elements</h4><p>In the previous article, you learned how to build level XML files in order to create playable levels. This article discusses how the internal parser works and how XML nodes become items on the game screen.&nbsp; Check out the video for this article at <a href="http://channel9.msdn.com/Series/FallFury/Part-6-Rendering-Level-Elements">http://channel9.msdn.com/Series/FallFury/Part-6-Rendering-Level-Elements</a>.&nbsp; For a complete, offline version of this series, you may <a href="http://media.ch9.ms/coding4fun/fallfury/FallFury.pdf">download a nicely formatted PDF of all the articles</a>.</p><h4>Project Interop – The C# Parser</h4><p>Thanks to classes such as <a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx">XmlSerializer</a> and <a href="http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx">XDocument</a>, parsing XML in .NET Framework is not a complicated task. Similarly, in the WinRT world there are alternatives such as <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.data.xml.dom.aspx">Windows::Data::Xml::Dom</a>. That being said, using the parser skeleton in C# this project leverages the existing codebase, adapting it to the specific level reading needs.</p><p>Start by creating a new WinRT project that is the part of the existing solution. Make sure that you create a Windows Runtime Component:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image002%5B3%5D-5.jpg"><img title="clip_image002" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image002_thumb-6.jpg" alt="clip_image002" width="624" height="380" border="0"></a></p><p>There are <a href="http://www.drdobbs.com/windows/winrt-the-new-runtime-in-windows-8/232200577">major differences</a> between the .NET and WinRT stacks, especially when it comes to building code that can be invoked from any potential WinRT project type, as is the case here. Make sure that the output of the newly created project is a Windows Runtime Component (<a href="http://www.thomgerdes.com/2011/12/winrt-internals-winmd-files.html">WinMD file</a>):</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image004%5B3%5D-3.jpg"><img title="clip_image004" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image004_thumb-4.jpg" alt="clip_image004" width="640" height="195" border="0"></a></p><p>The XMLReader project reads much more than the level data—it also manages internal XML metadata such as user scores. This article, however, focuses only on level-related aspects of the engine.</p><p><strong>Reader </strong>is the one core class used here. It contains the <strong>ReadXml</strong> method, which receives the file name and the type of the XML file to be read. Regardless of the name, the XML file type determines the parsing rules, the root lookup location, and the produced output. The tier (level set) and individual level data are stored internally in the application folder, and the score metadata is outside the sandbox in the application data folder:</p><p><pre class="brush: csharp">
async Task&lt;Object&gt; ReadXml(string fileName, XmlType type)
{
        StorageFile file = null;
        StorageFolder folder = null;
    
        if (type == XmlType.LEVEL || type == XmlType.TIERS)
        {
                folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
                folder = await folder.GetFolderAsync(&quot;Levels&quot;);
        }
        else if (type == XmlType.HIGHSCORE)
        {
                folder = ApplicationData.Current.LocalFolder;
                folder = await folder.GetFolderAsync(&quot;Meta&quot;);
        }
    
        file = await folder.GetFileAsync(fileName);
    
        Object returnValue = null;
        string data;
    
        using (IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read))
        {
                using (Stream inStream = Task.Run(() =&gt; readStream.AsStreamForRead()).Result)
                {
                        using (StreamReader reader = new StreamReader(inStream))
                        {
                                data = reader.ReadToEnd();
                        }
                }
        }
    
        if (type == XmlType.LEVEL)
        {
                returnValue = ExtractLevelData(data);
        }
        else if (type == XmlType.HIGHSCORE)
        {
                returnValue = ExtractScoreData(data);
        }
        else if (type == XmlType.TIERS)
        {
                returnValue = ExtractTierData(data);
        }
    
        return returnValue;
}
</pre></p><p>Before the level data is extracted, FallFury needs to know about the existing tiers pointing to those levels. That’s where <strong>ExtractTierData</strong>, an internal method that accepts a raw XML string and return a <strong>TierSet</strong> instance, comes in:</p><p><pre class="brush: csharp">
public sealed class TierSet
{
    public Tier[] Tiers { get; set; }
}
</pre></p><p>A <strong>Tier</strong> class has the following structure:</p><p><pre class="brush: csharp">
public sealed class Tier
{
    public string Name { get; set; }
    public string[] LevelNames { get; set; }
    public string[] LevelFiles { get; set; }
}
</pre></p><p>I am using the most fundamental types – arrays instead of generic collections, to maximize the portability of the code. The <strong>ExtractTierData </strong>method handles the XML-to-Object transformation:</p><p><pre class="brush: csharp">
TierSet ExtractTierData(string tierString)
{
        TierSet set = new TierSet();
    
        XDocument document = XDocument.Parse(tierString);
    
        set.Tiers = new Tier[document.Root.Elements().Count()];
    
        int tierCounter = 0;
    
        foreach (XElement element in document.Root.Elements())
        {
                Tier tier = new Tier();
                tier.Name = element.Attribute(&quot;name&quot;).Value;
        
                tier.LevelFiles = new string[element.Elements(&quot;level&quot;).Count()];
                tier.LevelNames = new string[element.Elements(&quot;level&quot;).Count()];
        
                
                int count = 0;
                foreach (XElement lElement in element.Elements(&quot;level&quot;))
                {
                        tier.LevelFiles[count] = lElement.Attribute(&quot;file&quot;).Value;
                        tier.LevelNames[count] = lElement.Attribute(&quot;name&quot;).Value;
                        count&#43;&#43;;
                }
        
                set.Tiers[tierCounter] = tier;
                tierCounter&#43;&#43;;
        }
    
        return set;
}
</pre></p><p>I am running a coupled array block here, utilizing one array for level names and another for file locations. This is a very basic implementation of a key-value pair that depends on code-based coupling. <strong>ExtractTierData</strong>, however, is not exposed publicly and the C&#43;&#43; layer of FallFury will not access it because <strong>TierSet</strong> is not exposed through a compatible async method. Looking back at <strong>ReadXml</strong>, might seem like the answer to this problem. But a <strong>Task&lt;Object&gt;</strong> is not an interop-compatible type, which means I use <strong>ReadXmlAsync</strong>, which proxies the call through an <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br206598.aspx">IAsyncOperation</a>:</p><p><pre class="brush: csharp">
public IAsyncOperation&lt;Object&gt; ReadXmlAsync(string filename, XmlType type)
{
    return (IAsyncOperation&lt;Object&gt;)AsyncInfo.Run((CancellationToken token) =&gt; ReadXml(filename, type));
}
</pre></p><p><a href="http://msdn.microsoft.com/en-us/library/hh779740.aspx">AsyncInfo.Run</a> starts a WinRT async operation and handles the returned result, regardless of the selected file path or type.</p><p>Level-based data is extracted in a similar manner to the tier data. The difference lies in the used internal models, as well as the node reading order:</p><p><pre class="brush: csharp">
Level ExtractLevelData(string levelString)
{
        XDocument document = XDocument.Parse(levelString);
    
        Level level = new Level();
        level.LevelMeta = new Meta();
     
        level.LevelMeta.Score = Convert.ToInt32(document.Root.Element(&quot;meta&quot;).Attribute(&quot;score&quot;).Value);
        level.LevelMeta.ButtonPrice = Convert.ToInt32(document.Root.Element(&quot;meta&quot;).Attribute(&quot;buttonPrice&quot;).Value)
        level.LevelMeta.LevelType = (LevelType)Convert.ToInt32(document.Root.Attribute(&quot;type&quot;).Value);
    
        int count = document.Root.Element(&quot;obstacles&quot;).Elements().Count();
        level.Obstacles = new Obstacle[count];
    
        count = 0;
        foreach (XElement element in document.Root.Element(&quot;obstacles&quot;).Elements())
        {
                Obstacle obstacle = new Obstacle();
                obstacle.HealthDamage = Convert.ToSingle(element.Attribute(&quot;healthDamage&quot;).Value);
                obstacle.InflictsDamage = Convert.ToBoolean(element.Attribute(&quot;inflictsDamage&quot;).Value);
                obstacle.Rotation = Convert.ToSingle(element.Attribute(&quot;rotation&quot;).Value);
                obstacle.Scale = Convert.ToSingle(element.Attribute(&quot;scale&quot;).Value);
                obstacle.X = Convert.ToSingle(element.Attribute(&quot;x&quot;).Value);
                obstacle.Y = Convert.ToSingle(element.Attribute(&quot;y&quot;).Value);
                obstacle.Type = (ObstacleType)Convert.ToInt32(element.Attribute(&quot;type&quot;).Value);
                level.Obstacles[count] = obstacle;
                count&#43;&#43;;
        }
    
        count = document.Root.Element(&quot;monsters&quot;).Elements().Count();
        level.Monsters = new Monster[count];
    
        count = 0;
        foreach (XElement element in document.Root.Element(&quot;monsters&quot;).Elements())
        {
                Monster monster = new Monster();
                monster.CriticalDamage = Convert.ToSingle(element.Attribute(&quot;criticalDamage&quot;).Value);
                monster.Damage = Convert.ToSingle(element.Attribute(&quot;damage&quot;).Value);
                monster.DefaultAmmo = Convert.ToInt32(element.Attribute(&quot;defaultAmmo&quot;).Value);
                monster.MaxHealth = Convert.ToSingle(element.Attribute(&quot;maxHealth&quot;).Value);
                monster.X = Convert.ToSingle(element.Attribute(&quot;x&quot;).Value);
                monster.Y = Convert.ToSingle(element.Attribute(&quot;y&quot;).Value);
                monster.VelocityX = Convert.ToSingle(element.Attribute(&quot;velocityX&quot;).Value);
                monster.Lifetime = Convert.ToSingle(element.Attribute(&quot;lifetime&quot;).Value);
                monster.Type = (MonsterType)Convert.ToInt32(element.Attribute(&quot;type&quot;).Value);
                monster.Bonus = Convert.ToInt32(element.Attribute(&quot;bonus&quot;).Value);
                monster.Scale = Convert.ToSingle(element.Attribute(&quot;scale&quot;).Value);
        
                level.Monsters[count] = monster;
                count&#43;&#43;;
        }
    
        count = document.Root.Element(&quot;buttons&quot;).Elements().Count();
        level.Buttons = new Button[count];
    
        count = 0;
        foreach (XElement element in document.Root.Element(&quot;buttons&quot;).Elements())
        {
                Button button = new Button();
        
                button.X = Convert.ToSingle(element.Attribute(&quot;x&quot;).Value);
                button.Y = Convert.ToSingle(element.Attribute(&quot;y&quot;).Value);
        
                level.Buttons[count] = button;
                count&#43;&#43;;
        }
    
        count = document.Root.Element(&quot;powerups&quot;).Elements().Count();
        level.Powerups = new Powerup[count];
    
        count = 0;
        foreach (XElement element in document.Root.Element(&quot;powerups&quot;).Elements())
        {
                Powerup powerup = new Powerup();
        
                powerup.X = Convert.ToSingle(element.Attribute(&quot;x&quot;).Value);
                powerup.Y = Convert.ToSingle(element.Attribute(&quot;y&quot;).Value);
                powerup.Category = (PowerupCategory)Convert.ToInt32(element.Attribute(&quot;category&quot;).Value);
                powerup.Type = (PowerupType)Convert.ToInt32(element.Attribute(&quot;type&quot;).Value);
                powerup.Lifespan = Convert.ToSingle(element.Attribute(&quot;lifespan&quot;).Value);
                powerup.Effect = Convert.ToSingle(element.Attribute(&quot;effect&quot;).Value);
        
                level.Powerups[count] = powerup;
                count&#43;&#43;;
        }
    
        Bear bear = new Bear();
        XElement bearElement = document.Root.Element(&quot;bear&quot;);
        bear.CriticalDamage = Convert.ToSingle(bearElement.Attribute(&quot;criticalDamage&quot;).Value);
        bear.Damage = Convert.ToSingle(bearElement.Attribute(&quot;damage&quot;).Value);
        bear.DefaultAmmo = Convert.ToInt32(bearElement.Attribute(&quot;defaultAmmo&quot;).Value);
        bear.MaxHealth = Convert.ToSingle(bearElement.Attribute(&quot;maxHealth&quot;).Value);
        bear.StartPosition = Convert.ToSingle(bearElement.Attribute(&quot;startPosition&quot;).Value);
        bear.Velocity = Convert.ToSingle(bearElement.Attribute(&quot;velocity&quot;).Value);
    
        level.GameBear = bear;
        
        return level;
}
</pre></p><p>As a result, the <strong>Level</strong> instance has an internal counterpart in the C&#43;&#43; project:</p><p><pre class="brush: csharp">
public sealed class Level
{
    public Bear GameBear { get; set; }
    public Meta LevelMeta { get; set; }
    public Obstacle[] Obstacles { get; set; }
    public Monster[] Monsters { get; set; }
    public Button[] Buttons { get; set; }
    public Powerup[] Powerups { get; set; }
}
</pre></p><h4>From C# to C&#43;&#43; - Leveraging the WinRT Component</h4><p>At this point, the C#-based WinRT component is complete and can be integrated into the C&#43;&#43; project. This can be done in two ways: either by adding a reference to the project itself or by adding a reference to the generated WinMD file. Both methods will ultimately produce the same output, but it’s easier to debug and modify coupled projects on the go, so I went with the first option.</p><p>To add a reference to an internal Windows Runtime Component project, right click on the C&#43;&#43; project in <strong>Solution Explorer</strong> and select <strong>Properties</strong>. You will see a dialog like this:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image006%5B3%5D-1.jpg"><img title="clip_image006" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image006_thumb-2.jpg" alt="clip_image006" width="567" height="403" border="0"></a></p><p>Select the <strong>Common Properties</strong> node in the tree on the left and open the <strong>Framework and References</strong> page:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image008%5B3%5D-2.jpg"><img title="clip_image008" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image008_thumb-3.jpg" alt="clip_image008" width="569" height="404" border="0"></a></p><p>In the sample screen capture above, the <strong>FallFury.XMLReader</strong> project is already added as a reference. For a new project, simply click on <strong>Add New Reference</strong> and add any compatible project or third-party extension. As soon as the reference is added, the publicly exposed methods can be accessed.</p><p>In <strong>DirectXPage.cpp</strong> I have a method called <strong>LoadLevelData</strong> that allows me to load the list of the registered levels from <strong>core.xml</strong> as well as build the visual tree for the menu items, whichallows players to select a level:</p><p><pre class="brush: cpp">
void DirectXPage::LoadLevelData()
{
    Coding4Fun::FallFury::XMLReader::Reader^ reader = ref new Coding4Fun::FallFury::XMLReader::Reader();
    Windows::Foundation::IAsyncOperation&lt;Platform::Object^&gt;^ result = reader-&gt;ReadXmlAsync(&quot;core.xml&quot;, Coding4Fun::FallFury::XMLReader::Models::XmlType::TIERS);
    result-&gt;Completed =
        ref new AsyncOperationCompletedHandler&lt;Platform::Object^&gt;(this, &amp;DirectXPage::OnLevelLoadCompleted);
}
</pre></p><p>Following the normal asynchronous pattern, as well as the structure of the method exposed in the Reader class, I am calling <strong>ReadXmlAsync</strong> and getting the result in <strong>OnLevelLoadCompleted</strong> when the operation reaches its final stage. It is worth mentioning that the associated <a href="http://msdn.microsoft.com/en-us/library/windows/apps/br206572.aspx">AsyncOperationCompletedHandler</a> is invoked even when the reading fails; therefore, the invocation of that callback does not on its own mean that the necessary data is obtained:</p><p>Here is what happens when <strong>OnLevelLoadCompleted</strong> is called:</p><p><pre class="brush: cpp">
void DirectXPage::OnLevelLoadCompleted(IAsyncOperation&lt;Platform::Object^&gt; ^op, AsyncStatus s)
{
    if (s == AsyncStatus::Completed)
    {
        auto set = (Coding4Fun::FallFury::XMLReader::Models::TierSet^)op-&gt;GetResults();
        
        auto tiers = set-&gt;Tiers;
        
        int levelCounter = 0;
        
        for (auto tier = tiers-&gt;begin(); tier != tiers-&gt;end(); tier&#43;&#43;)
        {
            StackPanel^ panel = ref new StackPanel();
            
            TextBlock^ levelTierTitle = ref new TextBlock();
            levelTierTitle-&gt;Text = (*tier)-&gt;Name;
            levelTierTitle-&gt;Style = (Windows::UI::Xaml::Style^)Application::Current-&gt;Resources-&gt;Lookup(&quot;LevelSelectTierItemText&quot;);
            levelTierTitle-&gt;RenderTransform = ref new TranslateTransform();
            panel-&gt;Children-&gt;Append(levelTierTitle);
            
            levelNames = (*tier)-&gt;LevelNames;
            auto levelFiles = (*tier)-&gt;LevelFiles;
            
            int max = levelNames-&gt;Length;
            
            for(int i = 0; i &lt; max; i&#43;&#43;)
            {
                MenuItem^ item = ref new MenuItem();
                item-&gt;Tag = levelCounter;
                item-&gt;Label = levelNames[i];
                item-&gt;HorizontalAlignment = Windows::UI::Xaml::HorizontalAlignment::Left;
                item-&gt;OnButtonSelected &#43;= ref new MenuItem::ButtonSelected(this, &amp;DirectXPage::OnLevelButtonSelected);
                item-&gt;RenderTransform = ref new TranslateTransform();
                
                m_renderer-&gt;Levels.Insert(levelCounter,levelFiles[i]);
                
                panel-&gt;Children-&gt;Append(item);
                levelCounter&#43;&#43;;
            }
            
            stkLevelContainer-&gt;Items-&gt;Append(panel);
        }
    }
}
</pre></p><p>Here, <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.foundation.asyncstatus">AsyncStatus</a> can also be <strong>Cancelled</strong> or <strong>Error</strong>, so checking for <strong>Complete</strong> ensures that the expected result is processed further inside the context of the callback.</p><p>As the returned <strong>TierSet</strong> exposes the <strong>Tiers</strong> array, I am simply iterating through each of the existing items to create independent tier blocks, grouped in <strong>StackPanel</strong> elements, coupled with level-specific <strong>MenuItem</strong> instances that present the user with a choice of playing a given level. The level ID is carried in the Tag property and it will be used to identify the selected button when <strong>DirectXPage::OnLevelButtonSelected</strong> is triggered:</p><h4>Reading Level-specific Data</h4><p>Level data is read in the <strong>GamePlayScreen</strong> once the selected menu button passes the name and level identifiers. The <strong>LoadLevelXml</strong> method is called as the screen begins to load, preparing all assets for the start of the game session:</p><p><pre class="brush: cpp">
void GamePlayScreen::LoadLevelXML()
{
    Coding4Fun::FallFury::XMLReader::Reader^ reader = ref new Coding4Fun::FallFury::XMLReader::Reader();
    
    Platform::String^ LevelName = Manager-&gt;Levels.Lookup(StaticDataHelper::CurrentLevelID);
    
    Windows::Foundation::IAsyncOperation&lt;Platform::Object^&gt;^ result = 
            reader-&gt;ReadXmlAsync(LevelName, Coding4Fun::FallFury::XMLReader::Models::XmlType::LEVEL);
    
        result-&gt;Completed =
            ref new AsyncOperationCompletedHandler&lt;Platform::Object^&gt;(this, &amp;GamePlayScreen::OnLevelLoadCompleted);
}
</pre></p><p>The selected ID passes from the menu screen to the game screen through <strong>CurrentLevelID</strong>, an intermediary value preserved in a <strong>StaticDataHelper</strong> class. The level file name is looked up based on the ID and then passed to <strong>ReadXmlAsync</strong> with the <strong>XmlType</strong> set to <strong>LEVEL</strong>. When the load completes, <strong>OnLevelLoadCompleted</strong> is invoked, and an additional helper class—<strong> LevelDataLoader</strong>—sets up the game components based on the received data:</p><p><pre class="brush: cpp">
void GamePlayScreen::OnLevelLoadCompleted(IAsyncOperation&lt;Platform::Object^&gt; ^op, AsyncStatus s)
{
        if (s == AsyncStatus::Completed)
        {
                InitializeSpriteBatch();    
        m_loader = ref new BasicLoader(Manager-&gt;m_d3dDevice.Get(), Manager-&gt;m_wicFactory.Get());
        CreateBear();
        
                LevelDataLoader^ loader = ref new LevelDataLoader((Coding4Fun::FallFury::XMLReader::Models::Level^)op-&gt;GetResults(), this);
        loader-&gt;SetupBear(GameBear);
        loader-&gt;SetupObstacles(m_obstacles);
        loader-&gt;SetupMonsters(m_monsters);
        loader-&gt;SetupButtons(m_buttons, m_buttonPrice);
        loader-&gt;SetupPowerups(m_powerups);
        m_currentLevelType = (LevelType) loader-&gt;CurrentLevel-&gt;LevelMeta-&gt;LevelType;
        
        StaticDataHelper::CurrentLevel = loader-&gt;CurrentLevel;
        StaticDataHelper::ButtonsTotal = loader-&gt;CurrentLevel-&gt;Buttons-&gt;Length;
        
        LoadTextures();
        
                CreateMonster();
                CreatePowerups();
        
        IsLevelLoaded = true;
        
        GameBear-&gt;TurnRight();
        m_particleSystem.CreatePreCachedParticleSets();
        LoadSounds();
        }
}
</pre></p><p>Each object is separated in its own method, such as <strong>SetupBear</strong> or <strong>SetupObstacles</strong>. <strong>SetupBear</strong>, for example, transforms the exposed managed <strong>Bear</strong> model to a native C&#43;&#43; <strong>Characters::Bear</strong> one:</p><p><pre class="brush: cpp">
void LevelDataLoader::SetupBear(Bear ^gameBear)
{
        gameBear-&gt;Position = float2(GetXPosition(CurrentLevel-&gt;GameBear-&gt;StartPosition), 0);    
    gameBear-&gt;MaxHealth = CurrentLevel-&gt;GameBear-&gt;MaxHealth;
    gameBear-&gt;CurrentHealth = CurrentLevel-&gt;GameBear-&gt;MaxHealth;
    gameBear-&gt;CurrentDamage = CurrentLevel-&gt;GameBear-&gt;Damage;
    gameBear-&gt;Velocity.y = CurrentLevel-&gt;GameBear-&gt;Velocity;
    gameBear-&gt;MaxCriticalDamage = CurrentLevel-&gt;GameBear-&gt;CriticalDamage;
    gameBear-&gt;Rotation = 0.0f;
}
</pre></p><h4>Conclusion</h4><p>Mixing C# and C&#43;&#43; components is not a complicated process. Nonetheless, it comes with specific restrictions and considerations, such as the format of the publicly exposed asynchronous calls. The above C#-based level loading engine highlights the fact that WinRT interoperability allows you to leverage the languages you know best in order to efficiently accomplish project tasks.</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:3090c59845c94007a593a14a0135ba1f">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-6-Rendering-Level-Elements</comments>
      <itunes:summary>Rendering Level ElementsIn the previous article, you learned how to build level XML files in order to create playable levels. This article discusses how the internal parser works and how XML nodes become items on the game screen.&amp;nbsp; Check out the video for this article at http://channel9.msdn.com/Series/FallFury/Part-6-Rendering-Level-Elements.&amp;nbsp; For a complete, offline version of this series, you may download a nicely formatted PDF of all the articles. Project Interop – The C# ParserThanks to classes such as XmlSerializer and XDocument, parsing XML in .NET Framework is not a complicated task. Similarly, in the WinRT world there are alternatives such as Windows::Data::Xml::Dom. That being said, using the parser skeleton in C# this project leverages the existing codebase, adapting it to the specific level reading needs. Start by creating a new WinRT project that is the part of the existing solution. Make sure that you create a Windows Runtime Component:  There are major differences between the .NET and WinRT stacks, especially when it comes to building code that can be invoked from any potential WinRT project type, as is the case here. Make sure that the output of the newly created project is a Windows Runtime Component (WinMD file):  The XMLReader project reads much more than the level data—it also manages internal XML metadata such as user scores. This article, however, focuses only on level-related aspects of the engine. Reader is the one core class used here. It contains the ReadXml method, which receives the file name and the type of the XML file to be read. Regardless of the name, the XML file type determines the parsing rules, the root lookup location, and the produced output. The tier (level set) and individual level data are stored internally in the application folder, and the score metadata is outside the sandbox in the application data folder: 
async Task&amp;lt;Object&amp;gt; ReadXml(string fileName, XmlType type)
{
        StorageFile file = null;
   </itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-6-Rendering-Level-Elements</link>
      <pubDate>Wed, 23 Jan 2013 23:57:17 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-6-Rendering-Level-Elements</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/7ae7/6a8080f8-5fdb-4614-9540-da3c77cc7ae7/FallFuryPart6_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/7ae7/6a8080f8-5fdb-4614-9540-da3c77cc7ae7/FallFuryPart6_220.jpg" height="124" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/7ae7/6a8080f8-5fdb-4614-9540-da3c77cc7ae7/FallFuryPart6_512.jpg" height="289" width="512"></media:thumbnail>      
      <dc:creator>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</dc:creator>
      <itunes:author>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-6-Rendering-Level-Elements/RSS</wfw:commentRss>
      <category>C#</category>
      <category>C++</category>
      <category>DirectX</category>
      <category>Windows Store App</category>
    </item>
  <item>
      <title>Fall Fury: Part 5 - Creating Levels</title>
      <description><![CDATA[<h4>Creating Levels</h4><p>One of the goals set when developing FallFury was making the game extensible in regards to playable levels. Furthermore, I thought that it would make sense from the development and testing perspective to have levels as a completely separate entity that can be modified as necessary. For example, when a new power-up was introduced, I wanted to add an extra line in a level file and test it out. This was ultimately achieved by creating an XML-based level engine and in this article I will describe the level structure and design process.</p><p>Check out the video for this article at <a href="http://channel9.msdn.com/Series/FallFury/Part-5-Creating-Levels">http://channel9.msdn.com/Series/FallFury/Part-5-Creating-Levels.</a>&nbsp; For a complete, offline version of this series, you may <a href="http://media.ch9.ms/coding4fun/fallfury/FallFury.pdf">download a nicely formatted PDF of all the articles</a>.</p><h4>The First Steps</h4><p>When I started working on the level engine concept, I began designing the potential XML file structure for the level and ended up with the following requirements:</p><ul><li><strong>Level Type Identifier</strong> – As different levels have different backgrounds and sound themes, there should be a way to mark a level type. There are currently four level types: dream, nightmare, space, and magic bean. </li><li><strong>The Starting Character Descriptor</strong> – When the game starts, the teddy bear has some initial, basic properties, such as maximum health level, horizontal position, and velocity. </li><li><strong>A Collection of Obstacles </strong>– For each level, obstacles are positioned differently, and it’s important to specify that. For some obstacles it might be desirable to disable the damage infliction component, while for others it might be good to maximize the damage caused by colliding with them. Also, there are multiple textures associated with different obstacle types, so I wanted to specify the obstacles to render regardless of the selected level type. </li><li><strong>A Collection of Monsters </strong>– Obstacles are not the only component that can damage the bear during gameplay. There are also monsters that can pop up and shoot at the main character. Similar to the bear, monsters represent a living entity and have some specific properties, such as the initial health, damage, starting position, velocity, and type. </li><li><strong>Buttons – </strong>These are the bonus point boosters in FallFury. The player collects as many of those as possible, and each of them should be individually positioned to form either a trail or a shape. </li><li><strong>Power-Ups</strong> – With the basic set of abilities, the bear is able to get some bonuses such as a cape that will speed-up his descent or a bubble that will protect him from incoming shells. </li></ul><p>The first build of the level engine integrated into FallFuryused percentage-based relative values to position elements on the screen. Although this seemed like a good idea at the time, it became problematic because</p><ul><li>It required the level to be a fixed size, which restricted element addition and level extension. </li><li>It caused problems with obstacles that needed to be scaled and therefore had a non-standard size. </li><li>Small modifications were harder to make because minimal adjustments would throw off the relative position. </li></ul><p>So, I switched to a pixel-based conditioning in which each position is relative to zero. With this in place, levels can be infinitely long (within the context of the machine’s rendering and memory capabilities)and extra elements can be more seamlessly added.</p><p>Additionally, levels need to be packaged together in individual sets, normally grouped by themes, without restriction. This is achieved with the help of an extra XML file,called <strong>core.xml</strong>, which keeps track of level tiers, and acts as a container that allows the developer to name and easily enable or disable specific levels .</p><p>The structure for the <strong>core.xml</strong> file looks like this:</p><p><pre class="brush: xml">
&lt;tiers&gt;
  &lt;tier name=&quot;GO, GO, TEDDY&quot;&gt;
    &lt;level name=&quot;mind travels&quot; file=&quot;GoGoTeddy\mind.xml&quot;&gt;&lt;/level&gt;
    &lt;level name=&quot;falling in&quot; file=&quot;Nightmare\full_pilot.xml&quot;&gt;&lt;/level&gt;
    &lt;level name=&quot;frontlines&quot; file=&quot;Nightmare\the_beginning.xml&quot;&gt;&lt;/level&gt;
    &lt;level name=&quot;the chase&quot; file=&quot;Nightmare\chasing_monsters.xml&quot;&gt;&lt;/level&gt;
  &lt;/tier&gt;
  &lt;tier name=&quot;SECRET GARDEN&quot;&gt;
    &lt;level name=&quot;bean stalking&quot; file=&quot;Garden\bean_stalking.xml&quot;/&gt;
    &lt;level name=&quot;thorn apart&quot; file=&quot;Garden\thorn_apart.xml&quot;/&gt;
  &lt;/tier&gt;
  &lt;!--&lt;tier name=&quot;Obstacle ***TEST***&quot;&gt;
    &lt;level name=&quot;Nightmare 0&quot; file=&quot;test\Obstacle\nightmare\0.xml&quot; /&gt;
    &lt;level name=&quot;Nightmare 1&quot; file=&quot;test\Obstacle\nightmare\1.xml&quot; /&gt;
    &lt;level name=&quot;Bean 0&quot; file=&quot;test\Obstacle\bean\0.xml&quot; /&gt;
    &lt;level name=&quot;Bean 1&quot; file=&quot;test\Obstacle\bean\1.xml&quot; /&gt;
    &lt;level name=&quot;Dream 0&quot; file=&quot;test\Obstacle\dream\0.xml&quot; /&gt;
    &lt;level name=&quot;Dream 1&quot; file=&quot;test\Obstacle\dream\1.xml&quot; /&gt;
  &lt;/tier&gt;--&gt;
  &lt;!--&lt;tier name=&quot;Death ***TEST***&quot;&gt;
    &lt;level name=&quot;Monster 0&quot; file=&quot;test\death\0.xml&quot; /&gt;
  &lt;/tier&gt;--&gt;
  &lt;!--&lt;tier name=&quot;Monster ***TEST***&quot;&gt;
    &lt;level name=&quot;0&quot; file=&quot;test\Monsters\0.xml&quot; /&gt;
    &lt;level name=&quot;1&quot; file=&quot;test\Monsters\1.xml&quot; /&gt;
    &lt;level name=&quot;2&quot; file=&quot;test\Monsters\2.xml&quot; /&gt;
    &lt;level name=&quot;3&quot; file=&quot;test\Monsters\3.xml&quot; /&gt;
    &lt;level name=&quot;4&quot; file=&quot;test\Monsters\4.xml&quot; /&gt;
    &lt;level name=&quot;5&quot; file=&quot;test\Monsters\5.xml&quot; /&gt;
    &lt;level name=&quot;6&quot; file=&quot;test\Monsters\6.xml&quot; /&gt;
    &lt;level name=&quot;7&quot; file=&quot;test\Monsters\7.xml&quot; /&gt;
    &lt;level name=&quot;8&quot; file=&quot;test\Monsters\8.xml&quot; /&gt;
    &lt;level name=&quot;9&quot; file=&quot;test\Monsters\9.xml&quot; /&gt;
    &lt;level name=&quot;10&quot; file=&quot;test\Monsters\10.xml&quot; /&gt;
  &lt;/tier&gt;--&gt;
  &lt;!--&lt;tier name=&quot;MEDALS *****TEST******&quot;&gt;
    &lt;level name=&quot;gold&quot; file=&quot;test\Medals\gold.xml&quot;&gt;&lt;/level&gt;
    &lt;level name=&quot;silver&quot; file=&quot;test\Medals\silver.xml&quot;&gt;&lt;/level&gt;
    &lt;level name=&quot;bronze&quot; file=&quot;test\Medals\bronze.xml&quot;&gt;&lt;/level&gt;
  &lt;/tier&gt;
  &lt;tier name=&quot;Buttons ***TEST***&quot;&gt;
    &lt;level name=&quot;1&quot; file=&quot;test\Buttons\single.xml&quot; /&gt;
    &lt;level name=&quot;Lots&quot; file=&quot;test\Buttons\multiple.xml&quot; /&gt;
  &lt;/tier&gt;
  &lt;tier name=&quot;Obstacles ***TEST***&quot;&gt;
    &lt;level name=&quot;Cape&quot; file=&quot;test\PowerUps\0.xml&quot; /&gt;
  &lt;/tier&gt;--&gt;
&lt;/tiers&gt;
</pre></p><p>Tiers that are commented out are ignored and the included levels aren’t on the game list. Also, the paths indicated for each <strong>file</strong> attribute—for each individual tier—are relative to the game folder itself. There is no limit on the number of subfolders that can be included in the path. The above structure will render this level set:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image002%5B3%5D-6.jpg"><img title="clip_image002" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image002_thumb-7.jpg" alt="clip_image002" width="640" height="360" border="0"></a></p><h4>The Level XML</h4><p>Let’s now take a look at the layout of the level descriptor XML file:</p><p><pre class="brush: xml">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;level type=&quot;0&quot;&gt;
  &lt;meta score=&quot;0&quot; buttonPrice=&quot;10&quot;&gt;&lt;/meta&gt;
  &lt;bear maxHealth=&quot;100&quot; startPosition=&quot;300&quot; velocity=&quot;8.0&quot; damage=&quot;11&quot; criticalDamage=&quot;20&quot; defaultAmmo=&quot;100&quot; /&gt;
  &lt;obstacles&gt;
    &lt;obstacle type=&quot;1&quot; x=&quot;119&quot; y=&quot;2300&quot; inflictsDamage=&quot;true&quot; healthDamage=&quot;5&quot; rotation=&quot;3.14&quot; scale=&quot;1&quot; /&gt;
    &lt;obstacle type=&quot;3&quot; x=&quot;534.5&quot; y=&quot;3000&quot; inflictsDamage=&quot;true&quot; healthDamage=&quot;5&quot; rotation=&quot;0&quot; scale=&quot;1&quot; /&gt;
    &lt;obstacle type=&quot;3&quot; x=&quot;534.5&quot; y=&quot;3300&quot; inflictsDamage=&quot;true&quot; healthDamage=&quot;5&quot; rotation=&quot;0&quot; scale=&quot;1&quot; /&gt;
    &lt;obstacle type=&quot;1&quot; x=&quot;119&quot; y=&quot;4200&quot; inflictsDamage=&quot;true&quot; healthDamage=&quot;5&quot; rotation=&quot;3.14&quot; scale=&quot;1&quot; /&gt;
    &lt;obstacle type=&quot;2&quot; x=&quot;546&quot; y=&quot;5000&quot; inflictsDamage=&quot;true&quot; healthDamage=&quot;5&quot; rotation=&quot;0&quot; scale=&quot;1&quot; /&gt;
    &lt;obstacle type=&quot;1&quot; x=&quot;119&quot; y=&quot;5800&quot; inflictsDamage=&quot;true&quot; healthDamage=&quot;5&quot; rotation=&quot;3.14&quot; scale=&quot;1&quot; /&gt;
    &lt;obstacle type=&quot;2&quot; x=&quot;546&quot; y=&quot;6600&quot; inflictsDamage=&quot;true&quot; healthDamage=&quot;5&quot; rotation=&quot;0&quot; scale=&quot;1&quot; /&gt;
  &lt;/obstacles&gt;
  &lt;monsters&gt;
    &lt;monster lifetime=&quot;3000&quot; scale=&quot;.2&quot; velocityX=&quot;2&quot; velocityY=&quot;2&quot; type=&quot;0&quot; x=&quot;460&quot; y=&quot;19900&quot; maxHealth=&quot;80&quot; bonus=&quot;100&quot; lives=&quot;0&quot; damage=&quot;10&quot; criticalDamage=&quot;8&quot; defaultAmmo=&quot;50&quot; /&gt;
    &lt;monster lifetime=&quot;3000&quot; scale=&quot;.2&quot; velocityX=&quot;2&quot; velocityY=&quot;2&quot; type=&quot;1&quot; x=&quot;460&quot; y=&quot;25000&quot; maxHealth=&quot;80&quot; bonus=&quot;100&quot; lives=&quot;0&quot; damage=&quot;10&quot; criticalDamage=&quot;8&quot; defaultAmmo=&quot;50&quot; /&gt;
    &lt;monster lifetime=&quot;3000&quot; scale=&quot;.2&quot; velocityX=&quot;2&quot; velocityY=&quot;2&quot; type=&quot;2&quot; x=&quot;460&quot; y=&quot;34500&quot; maxHealth=&quot;80&quot; bonus=&quot;100&quot; lives=&quot;0&quot; damage=&quot;10&quot; criticalDamage=&quot;8&quot; defaultAmmo=&quot;50&quot; /&gt;
    &lt;monster lifetime=&quot;6000&quot; scale=&quot;.4&quot; velocityX=&quot;2&quot; velocityY=&quot;2&quot; type=&quot;3&quot; x=&quot;460&quot; y=&quot;41400&quot; maxHealth=&quot;180&quot; bonus=&quot;100&quot; lives=&quot;0&quot; damage=&quot;17&quot; criticalDamage=&quot;8&quot; defaultAmmo=&quot;50&quot; /&gt;
  &lt;/monsters&gt;
  &lt;buttons&gt;
    &lt;button x=&quot;300&quot; y=&quot;800&quot; /&gt;
    &lt;button x=&quot;360&quot; y=&quot;800&quot; /&gt;
    &lt;button x=&quot;300&quot; y=&quot;860&quot; /&gt;
    &lt;button x=&quot;360&quot; y=&quot;860&quot; /&gt;
    &lt;button x=&quot;300&quot; y=&quot;920&quot; /&gt;
    &lt;button x=&quot;360&quot; y=&quot;920&quot; /&gt;
    &lt;button x=&quot;300&quot; y=&quot;980&quot; /&gt;
    &lt;button x=&quot;360&quot; y=&quot;980&quot; /&gt;
  &lt;/buttons&gt;
  &lt;powerups&gt;
    &lt;powerup category=&quot;1&quot; type=&quot;4&quot; x=&quot;140&quot; y=&quot;9200&quot; effect=&quot;3&quot; lifespan=&quot;4&quot;&gt;&lt;/powerup&gt;
    &lt;powerup category=&quot;1&quot; type=&quot;3&quot; x=&quot;480&quot; y=&quot;19800&quot; effect=&quot;10&quot; lifespan=&quot;6&quot;&gt;&lt;/powerup&gt;
    &lt;powerup category=&quot;1&quot; type=&quot;0&quot; x=&quot;480&quot; y=&quot;27500&quot; effect=&quot;10&quot; lifespan=&quot;6&quot;&gt;&lt;/powerup&gt;
    &lt;powerup category=&quot;1&quot; type=&quot;1&quot; x=&quot;100&quot; y=&quot;34000&quot; effect=&quot;10&quot; lifespan=&quot;6&quot;&gt;&lt;/powerup&gt;
    &lt;powerup category=&quot;1&quot; type=&quot;0&quot; x=&quot;100&quot; y=&quot;41200&quot; effect=&quot;10&quot; lifespan=&quot;6&quot;&gt;&lt;/powerup&gt;
  &lt;/powerups&gt;
&lt;/level&gt;
</pre></p><p>The opening <strong>level</strong> tag carries a type attribute. This is level theme flag. It can be set to one of the three four values:</p><ul><li><strong>0</strong> – The Nightmare Theme </li><li><strong>1</strong> – The Magic Bean Theme </li><li><strong>2</strong> – The Dream Theme </li><li><strong>3</strong> – The Space Theme </li></ul><p>You can see the design differences in the images below:</p><table border="0" cellspacing="0" cellpadding="0"><tbody><tr><td valign="top" width="360"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image004%5B3%5D-4.jpg"><img title="clip_image004" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image004_thumb-5.jpg" alt="clip_image004" width="270" height="270" border="0"></a></p></td><td valign="top" width="360"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image006%5B3%5D-2.jpg"><img title="clip_image006" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image006_thumb-3.jpg" alt="clip_image006" width="269" height="270" border="0"></a></p></td></tr><tr><td valign="top" width="360"><p>Nightmare</p></td><td valign="top" width="360"><p>Magic Bean</p></td></tr><tr><td valign="top" width="719">&nbsp;</td></tr><tr><td valign="top" width="360"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image008%5B3%5D-3.jpg"><img title="clip_image008" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image008_thumb-4.jpg" alt="clip_image008" width="269" height="270" border="0"></a></p></td><td valign="top" width="360"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image010%5B3%5D-1.jpg"><img title="clip_image010" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image010_thumb-2.jpg" alt="clip_image010" width="269" height="270" border="0"></a></p></td></tr><tr><td valign="top" width="360"><p>Dream</p></td><td valign="top" width="360"><p>Space</p></td></tr></tbody></table><p>Remember, that obstacles and the level theme itself do not influence much other than the background and soundboard.</p><p>Once the type is specified, the <strong>meta</strong> tag brings up the <strong>score</strong> and <strong>buttonPrice</strong> attributes. If you for some reason want to create a level including an initial score, you can specify it here. And because buttons are fixed bonus assets that are all created equal, each of them carries a given bonus point weight. The score based on the collected buttons is calculated at the end of the game and relies on the value specified in the <strong>meta</strong> tag.</p><h4>Obstacles</h4><p>Next comes the obstacle collection, which is represented by the <strong>obstacles</strong> tag. This tag is required even if there are no obstacles on a given level. Simply use <strong>&lt;obstacles /&gt;</strong> as necessary. Each child node represents an instance of an obstacle that can be choosen from the following enum:</p><p><pre class="brush: cpp">
enum class ObstacleType
{
    OT_CLOUD = 0,
    OT_SPIKE_NIGHTMARE_LARGE = 1,
    OT_SPIKE_NIGHTMARE_MEDIUM = 2,
    OT_SPIKE_NIGHTMARE_SMALL = 3,
    OT_BEAN_A = 4,
    OT_BEAN_B = 5,
    OT_BEAN_C = 6,
    OT_BEAN_D = 7,
    OT_BEAN_E = 8,
    OT_SPACE_ROCKET = 9,
    OT_SPACE_COMET_A = 10,
    OT_SPACE_COMET_B = 11,
    OT_SPACE_SATELLITE = 12,
    OT_SPACE_UFO = 13,
    OT_SPACE_BALL = 14
};
</pre></p><p>Here is the complete table showing the appearance of each of them:</p><table border="0" cellspacing="0" cellpadding="0"><tbody><tr><td width="246"><p>OT_CLOUD</p></td><td valign="top" width="474"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image012%5B3%5D-3.jpg"><img title="clip_image012" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image012_thumb-3.jpg" alt="clip_image012" width="285" height="103" border="0"></a></p></td></tr><tr><td valign="top" width="246">&nbsp;</td><td valign="top" width="474">&nbsp;</td></tr><tr><td width="246"><p>OT_SPIKE_NIGHTMARE_LARGE</p></td><td valign="top" width="474"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image014%5B3%5D-3.jpg"><img title="clip_image014" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image014_thumb-3.jpg" alt="clip_image014" width="126" height="116" border="0"></a></p></td></tr><tr><td width="246">&nbsp;</td><td valign="top" width="474">&nbsp;</td></tr><tr><td width="246"><p>OT_SPIKE_NIGHTMARE_MEDIUM</p></td><td valign="top" width="474"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image016%5B3%5D-2.jpg"><img title="clip_image016" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image016_thumb-3.jpg" alt="clip_image016" width="234" height="131" border="0"></a></p></td></tr><tr><td width="246">&nbsp;</td><td valign="top" width="474">&nbsp;</td></tr><tr><td width="246"><p>OT_SPIKE_NIGHTMARE_SMALL</p></td><td valign="top" width="474"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image018%5B3%5D-2.jpg"><img title="clip_image018" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image018_thumb-2.jpg" alt="clip_image018" width="245" height="126" border="0"></a></p></td></tr><tr><td width="246">&nbsp;</td><td valign="top" width="474">&nbsp;</td></tr><tr><td width="246"><p>OT_BEAN_A</p></td><td valign="top" width="474"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image020%5B3%5D-1.jpg"><img title="clip_image020" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image020_thumb-1.jpg" alt="clip_image020" width="281" height="174" border="0"></a></p></td></tr><tr><td width="246">&nbsp;</td><td valign="top" width="474">&nbsp;</td></tr><tr><td width="246"><p>OT_BEAN_B</p></td><td valign="top" width="474"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image022%5B3%5D-1.jpg"><img title="clip_image022" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image022_thumb-1.jpg" alt="clip_image022" width="133" height="165" border="0"></a></p></td></tr><tr><td width="246">&nbsp;</td><td valign="top" width="474">&nbsp;</td></tr><tr><td width="246"><p>OT_BEAN_C</p></td><td valign="top" width="474"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image024%5B3%5D-1.jpg"><img title="clip_image024" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image024_thumb-1.jpg" alt="clip_image024" width="179" height="152" border="0"></a></p></td></tr><tr><td width="246">&nbsp;</td><td valign="top" width="474">&nbsp;</td></tr><tr><td width="246"><p>OT_BEAN_D</p></td><td valign="top" width="474"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image026%5B3%5D-1.jpg"><img title="clip_image026" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image026_thumb-1.jpg" alt="clip_image026" width="197" height="198" border="0"></a></p></td></tr><tr><td width="246">&nbsp;</td><td valign="top" width="474">&nbsp;</td></tr><tr><td width="246"><p>OT_BEAN_E</p></td><td valign="top" width="474"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image028%5B3%5D-1.jpg"><img title="clip_image028" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image028_thumb-1.jpg" alt="clip_image028" width="217" height="181" border="0"></a></p></td></tr><tr><td width="246">&nbsp;</td><td valign="top" width="474">&nbsp;</td></tr><tr><td width="246"><p>OT_SPACE_ROCKET</p></td><td valign="top" width="474"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image030%5B3%5D-1.jpg"><img title="clip_image030" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image030_thumb-1.jpg" alt="clip_image030" width="165" height="181" border="0"></a></p></td></tr><tr><td valign="top" width="246">&nbsp;</td><td valign="top" width="474">&nbsp;</td></tr><tr><td width="246"><p>OT_SPACE_COMET_A</p></td><td valign="top" width="474"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image032%5B3%5D-1.jpg"><img title="clip_image032" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image032_thumb-1.jpg" alt="clip_image032" width="186" height="186" border="0"></a></p></td></tr><tr><td width="246">&nbsp;</td><td valign="top" width="474">&nbsp;</td></tr><tr><td width="246"><p>OT_SPACE_COMET_B</p></td><td valign="top" width="474"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image034%5B3%5D.jpg"><img title="clip_image034" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image034_thumb.jpg" alt="clip_image034" width="131" height="132" border="0"></a></p></td></tr><tr><td width="246">&nbsp;</td><td valign="top" width="474">&nbsp;</td></tr><tr><td width="246"><p>OT_SPACE_SATELLITE</p></td><td valign="top" width="474"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image036%5B3%5D.jpg"><img title="clip_image036" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image036_thumb.jpg" alt="clip_image036" width="150" height="197" border="0"></a></p></td></tr><tr><td width="246">&nbsp;</td><td valign="top" width="474">&nbsp;</td></tr><tr><td width="246"><p>OT_SPACE_UFO</p></td><td valign="top" width="474"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image038%5B3%5D.jpg"><img title="clip_image038" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image038_thumb.jpg" alt="clip_image038" width="202" height="187" border="0"></a></p></td></tr><tr><td width="246">&nbsp;</td><td valign="top" width="474">&nbsp;</td></tr><tr><td width="246"><p>OT_SPACE_BALL</p></td><td valign="top" width="474"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image040%5B3%5D.jpg"><img title="clip_image040" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image040_thumb.jpg" alt="clip_image040" width="179" height="189" border="0"></a></p></td></tr></tbody></table><p>No matter how the obstacles are positioned, they will either be located in the visible area or displaced outside the viewport and not displayed. The ultimate position is taken from the obstacle size and is relative to the center of the texture. For example, if an obstacle texture is 400- pixels wide, the X-relative position should be set to 200. If the position differs from the starting one, however, the obstacle texture is cut to include the area that fits in the 768 pixel wide playable zone visible. There are no restrictions regarding the Y position.</p><p>To help in level creation, some obstacles have pre-defined left and right margins. For example:</p><ul><li><strong>OT_BEAN_A:</strong> 269.5 (Left), 498.5 (right, with 3.14 rotation) </li><li><strong>OT_BEAN_B:</strong> 128.5 (left), 638.5 (right, with 3.14 rotation) </li><li><strong>OT_BEAN_C:</strong> 172 (left), 596 (right, with 3.14 rotation) </li><li><strong>OT_BEAN_D:</strong> 188.5 (left), 579.5 (right, with 3.14 rotation) </li><li><strong>OT_BEAN_E:</strong> 206.5 (left), 561.5 (right, with 3.14 rotation) </li></ul><p>The <strong>inflictsDamage</strong> attribute determines whether the obstacle harms the main character. If it is set to <strong>false</strong>, the character will still make the sound of colliding with it but will not lose any health points. The primary use for this attribute is level testing.If it is set to <strong>true</strong>, the character will loose the amount of health points indicated by the <strong>healthDamage</strong> attribute.</p><p>The <strong>rotation</strong> and <strong>scale</strong> attributes can be used to flip and resize the texture as needed. Rotation is measured in radians, and the scale is a normalized value in which 1.0 represents 100% of the scale.</p><h4>Monsters</h4><p>As with obstacles, the <strong>monsters</strong> node should never be omitted from the file and should at least contain a placeholder: <strong>&lt;monsters /&gt;</strong>. Unlike obstacles, however, monsters are dynamic and do not have fixed positions. Moreover, monsters have limited active time during gameplay. The first attribute,<strong>lifetime</strong>, determines the length of the fall during which the monster will be visible in the viewport. With the <strong>y</strong> attribute as the Y-based position at which the monster appears, at the <strong>y&#43;lifetime</strong> position the monster simply flies away if not killed.</p><p>The <strong>scale</strong> attribute carries the same purpose as the one for the obstacle—normalized texture size relative to the size of the original image file. As such, the level designer does not have to worry about linking the width and height of the monster when resizing and can instead use a percentage-like value to scale the monster up or down, simultaneously modifying both the width and the height with zero stretching.</p><p>Nextup are <strong>velocityX</strong> and <strong>velocityY</strong>. These two attributes are used to set the motion velocity when the monster is already visible. Instead of being a static shooting entity, the enemy moves on a randomized zig-zag path at the bottom of the screen. The horizontal and vertical displacement—in pixels, per update cycle—is individually set through the values carried by the above-mentioned attributes. If necessary, this functionality can be disabled in the code-behind by assigning a fixed value for the vertical and horizontal movement for all monsters that are being loaded on a given level.</p><p>The monster type is an <strong>integer</strong> value that is translated in a value from the following enum (located in <strong>MonsterType.h</strong>):</p><p><pre class="brush: cpp">
enum class MonsterType
{
    MT_NIGHTMARE_A = 0,
    MT_NIGHTMARE_B = 1,
    MT_NIGHTMARE_C = 2,
    MT_MAGICBEAN_A = 3,
    MT_MAGICBEAN_B = 4,
    MT_MAGICBEAN_C = 5,
    MT_CANDYLAND_A = 6,
    MT_CANDYLAND_B = 7,
    MT_CANDYLAND_C = 8,
    MT_CANDYLAND_D = 9,
    MT_CANDYLAND_E = 10
};
</pre></p><p>Here is a table that shows the texture associated with each identifier:</p><table border="0" cellspacing="0" cellpadding="0"><tbody><tr><td width="162"><p>MT_NIGHTMARE_A</p></td><td valign="top" width="216"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image042%5B3%5D.jpg"><img title="clip_image042" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image042_thumb.jpg" alt="clip_image042" width="132" height="130" border="0"></a></p></td></tr><tr><td width="162">&nbsp;</td><td valign="top" width="216">&nbsp;</td></tr><tr><td width="162"><p>MT_NIGHTMARE_B</p></td><td valign="top" width="216"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image044%5B3%5D.jpg"><img title="clip_image044" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image044_thumb.jpg" alt="clip_image044" width="111" height="140" border="0"></a></p></td></tr><tr><td width="162">&nbsp;</td><td valign="top" width="216">&nbsp;</td></tr><tr><td width="162"><p>MT_NIGHTMARE_C</p></td><td valign="top" width="216"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image046%5B3%5D.jpg"><img title="clip_image046" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image046_thumb.jpg" alt="clip_image046" width="79" height="139" border="0"></a></p></td></tr><tr><td width="162">&nbsp;</td><td valign="top" width="216">&nbsp;</td></tr><tr><td width="162"><p>MT_MAGICBEAN_A</p></td><td valign="top" width="216"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image048%5B3%5D.jpg"><img title="clip_image048" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image048_thumb.jpg" alt="clip_image048" width="200" height="136" border="0"></a></p></td></tr><tr><td width="162">&nbsp;</td><td valign="top" width="216">&nbsp;</td></tr><tr><td width="162"><p>MT_MAGICBEAN_B</p></td><td valign="top" width="216"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image050%5B3%5D.jpg"><img title="clip_image050" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image050_thumb.jpg" alt="clip_image050" width="74" height="139" border="0"></a></p></td></tr><tr><td width="162">&nbsp;</td><td valign="top" width="216">&nbsp;</td></tr><tr><td width="162"><p>MT_MAGICBEAN_C</p></td><td valign="top" width="216"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image052%5B3%5D.jpg"><img title="clip_image052" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image052_thumb.jpg" alt="clip_image052" width="123" height="140" border="0"></a></p></td></tr><tr><td width="162">&nbsp;</td><td valign="top" width="216">&nbsp;</td></tr><tr><td width="162"><p>MT_CANDYLAND_A</p></td><td valign="top" width="216"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image054%5B3%5D.jpg"><img title="clip_image054" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image054_thumb.jpg" alt="clip_image054" width="94" height="106" border="0"></a></p></td></tr><tr><td width="162">&nbsp;</td><td valign="top" width="216">&nbsp;</td></tr><tr><td width="162"><p>MT_CANDYLAND_B</p></td><td valign="top" width="216"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image056%5B3%5D.jpg"><img title="clip_image056" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image056_thumb.jpg" alt="clip_image056" width="64" height="117" border="0"></a></p></td></tr><tr><td width="162">&nbsp;</td><td valign="top" width="216">&nbsp;</td></tr><tr><td width="162"><p>MT_CANDYLAND_C</p></td><td valign="top" width="216"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image058%5B3%5D.jpg"><img title="clip_image058" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image058_thumb.jpg" alt="clip_image058" width="121" height="140" border="0"></a></p></td></tr><tr><td width="162">&nbsp;</td><td valign="top" width="216">&nbsp;</td></tr><tr><td width="162"><p>MT_CANDYLAND_D</p></td><td valign="top" width="216"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image060%5B3%5D.jpg"><img title="clip_image060" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image060_thumb.jpg" alt="clip_image060" width="187" height="138" border="0"></a></p></td></tr><tr><td width="162">&nbsp;</td><td valign="top" width="216">&nbsp;</td></tr><tr><td width="162"><p>MT_CANDYLAND_E</p></td><td valign="top" width="216"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image062%5B3%5D.jpg"><img title="clip_image062" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image062_thumb.jpg" alt="clip_image062" width="123" height="139" border="0"></a></p></td></tr><tr><td width="162">&nbsp;</td><td valign="top" width="216">&nbsp;</td></tr></tbody></table><p>Each monster has three separate textures associated with it. The three textures are cycled inside the update loop for each monster entity when the monster becomes visible, creating the movement effect:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image063%5B3%5D.png"><img title="clip_image063" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image063_thumb.png" alt="clip_image063" width="444" height="155" border="0"></a></p><p>Each monster currently shoots only one type of ammo: a red plasma ball. Be aware, however, that there is a preprogrammed condition in which the last monster in the XML file collection is automatically considered the final boss. This means the <strong>scale</strong>, <strong>maxHealth</strong> and <strong>lifetime</strong> properties must be manually adjusted to reflect the effect. Without doing so, the last monster will, regardless of the XML setting, switch in-game to a triple fireball shot that inflicts three times the damage indicated by the <strong>damage</strong> attribute:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image065%5B3%5D.jpg"><img title="clip_image065" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image065_thumb.jpg" alt="clip_image065" width="345" height="279" border="0"></a></p><p>Each monster can have limited ammo as set by the <strong>defaultAmmo</strong> attribute. In the case that the ammo is exhausted before the monster expires, the monster will continue its motion at the bottom of the screen without inflicting direct damage to the main character.</p><h4>Buttons</h4><p>These are the least complex entities and only carry an X and a Y position. Given those coordinates, relative to the left margin of the visible area, a button texture is rendered:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image067%5B3%5D.jpg"><img title="clip_image067" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image067_thumb.jpg" alt="clip_image067" width="408" height="258" border="0"></a></p><p>Once picked-up, the button counter is increased by one and the meta-score incremented by the value set in the <strong>meta</strong> tag at the beginning of the level XML as long as the feature is activated in the code-behind.</p><h4>Power-ups</h4><p>To make the game more fun, there are bonus elements that can be picked up by the bear in order to enhance its performance or protection. These elements are declared in the <strong>&lt;powerups/&gt;</strong> collection. First and foremost, it is important to declare whether the power-up is positive or negative. In the current version of FallFury, only positive power-ups are included. Nonetheless, the harness for negative ones is already integrated in the parser. Therefore, the <strong>category</strong> attribute should be set to 1 if the power-up has a positive effect and 0 for a negative effect. This value will only have an effect over the sound played when the bonus is collected.</p><p>The power-up type can be one of the following (enum located in <strong>PoweupType.h</strong>):</p><p><pre class="brush: cpp">
enum class PowerupType
{
    HEALTH = 0,
    HELMET = 1,
    PARACHUTE = 2,
    BUBBLE = 3,
    CAPE = 4,
    AXE = 5,
    BOOMERANG = 6,
    HAMMER = 7,
    KNIFE = 8,
    PLASMA_BALL = 9,
    CIRCLE = 10
};
</pre></p><p>&nbsp;</p><p>The table below shows the power-up texture appearance. Behaviors are already defined in the game and influenced by only the <strong>effect</strong> and <strong>lifespan</strong> (seconds) attributes:</p><table border="1" cellspacing="0" cellpadding="0"><tbody><tr><td width="120"><p>HEALTH</p></td><td width="360"><p>Restores the character health, incremented by the value in <strong>effect</strong>. The <strong>lifespan</strong> attribute is ignored.</p></td><td valign="top" width="72"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image069%5B3%5D.jpg"><img title="clip_image069" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image069_thumb.jpg" alt="clip_image069" width="52" height="52" border="0"></a></p></td></tr><tr><td width="120"><p>HELMET</p></td><td width="360"><p>Adds a helmet to the bear, setting the maximum health to the <strong>effect</strong> value. Active for the duration of <strong>lifespan</strong>.</p></td><td valign="top" width="72"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image071%5B3%5D.jpg"><img title="clip_image071" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image071_thumb.jpg" alt="clip_image071" width="51" height="53" border="0"></a></p></td></tr><tr><td width="120"><p>PARACHUTE</p></td><td width="360"><p>Slows down the fall of the bear, setting the descent velocity to the <strong>effect</strong> value. Active for the duration of <strong>lifespan</strong>.</p></td><td valign="top" width="72"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image073%5B3%5D.jpg"><img title="clip_image073" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image073_thumb.jpg" alt="clip_image073" width="52" height="52" border="0"></a></p></td></tr><tr><td width="120"><p>BUBBLE</p></td><td width="360"><p>Wraps the character in a protective bubble, setting the maximum health to the value of the <strong>effect</strong> attribute. Active for the duration of <strong>lifespan</strong>.</p></td><td valign="top" width="72"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image075%5B3%5D.jpg"><img title="clip_image075" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image075_thumb.jpg" alt="clip_image075" width="52" height="50" border="0"></a></p></td></tr><tr><td width="120"><p>CAPE</p></td><td width="360"><p>Accelerates the descent by multiplying the velocity by the value of <strong>effect</strong>. Active for the duration of <strong>lifespan</strong>.</p></td><td valign="top" width="72"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image077%5B3%5D.jpg"><img title="clip_image077" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image077_thumb.jpg" alt="clip_image077" width="52" height="52" border="0"></a></p></td></tr><tr><td width="120"><p>AXE</p></td><td width="360"><p>Sets the current character weapon to an axe. The damage is determined by the <strong>effect</strong> attribute and <strong>lifespan</strong> is ignored.</p></td><td valign="top" width="72"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image079%5B3%5D.jpg"><img title="clip_image079" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image079_thumb.jpg" alt="clip_image079" width="52" height="54" border="0"></a></p></td></tr><tr><td width="120"><p>BOOMERANG</p></td><td width="360"><p>Sets the current character weapon to a boomerang. The damage is determined by the <strong>effect</strong> attribute and <strong>lifespan</strong> is ignored.</p></td><td valign="top" width="72"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image081%5B3%5D.jpg"><img title="clip_image081" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image081_thumb.jpg" alt="clip_image081" width="51" height="52" border="0"></a></p></td></tr><tr><td width="120"><p>HAMMER</p></td><td width="360"><p>Sets the current character weapon to a hammer. The damage is determined by the <strong>effect</strong> attribute and <strong>lifespan</strong> is ignored.</p></td><td valign="top" width="72"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image083%5B3%5D.jpg"><img title="clip_image083" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image083_thumb.jpg" alt="clip_image083" width="52" height="52" border="0"></a></p></td></tr><tr><td width="120"><p>KNIFE</p></td><td width="360"><p>Sets the current character weapon to a knife. The damage is determined by the <strong>effect</strong> attribute and <strong>lifespan</strong> is ignored.</p></td><td valign="top" width="72"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image085%5B3%5D.jpg"><img title="clip_image085" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image085_thumb.jpg" alt="clip_image085" width="52" height="52" border="0"></a></p></td></tr><tr><td width="120"><p>PLASMA_BALL</p></td><td width="360"><p>Sets the current character weapon to a plasma ball. The damage is determined by the <strong>effect</strong> attribute and <strong>lifespan</strong> is ignored.</p></td><td valign="top" width="72"><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image087%5B3%5D.jpg"><img title="clip_image087" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image087_thumb.jpg" alt="clip_image087" width="54" height="52" border="0"></a></p></td></tr></tbody></table><p>CIRCLE is a helper power-up that has no effect on the bear and is instead used as an additional texture overlay along with any other power-up in order to create a pulsating circle effect.</p><h4>Conclusion</h4><p>FallFury ships with a dozen of sample levels that showcase all of the elements described in the article. At the moment, a level editor is in the works, but it isn’t too complicated to build XML files manually. To do so, you need to consider the pixel-based locations and ensure that they’re all in the visible area—the game engine will automatically handle all other displacements and adjustments.</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:3a3c8f6f0baa49dab538a14a01384bb7">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-5-Creating-Levels</comments>
      <itunes:summary>Creating LevelsOne of the goals set when developing FallFury was making the game extensible in regards to playable levels. Furthermore, I thought that it would make sense from the development and testing perspective to have levels as a completely separate entity that can be modified as necessary. For example, when a new power-up was introduced, I wanted to add an extra line in a level file and test it out. This was ultimately achieved by creating an XML-based level engine and in this article I will describe the level structure and design process. Check out the video for this article at http://channel9.msdn.com/Series/FallFury/Part-5-Creating-Levels.&amp;nbsp; For a complete, offline version of this series, you may download a nicely formatted PDF of all the articles. The First StepsWhen I started working on the level engine concept, I began designing the potential XML file structure for the level and ended up with the following requirements: Level Type Identifier – As different levels have different backgrounds and sound themes, there should be a way to mark a level type. There are currently four level types: dream, nightmare, space, and magic bean. The Starting Character Descriptor – When the game starts, the teddy bear has some initial, basic properties, such as maximum health level, horizontal position, and velocity. A Collection of Obstacles – For each level, obstacles are positioned differently, and it’s important to specify that. For some obstacles it might be desirable to disable the damage infliction component, while for others it might be good to maximize the damage caused by colliding with them. Also, there are multiple textures associated with different obstacle types, so I wanted to specify the obstacles to render regardless of the selected level type. A Collection of Monsters – Obstacles are not the only component that can damage the bear during gameplay. There are also monsters that can pop up and shoot at the main character. Similar to the bear, monsters r</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-5-Creating-Levels</link>
      <pubDate>Wed, 23 Jan 2013 23:57:11 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-5-Creating-Levels</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/b079/411aa110-67a6-4cda-9606-e3473f1bb079/FallFuryPart5_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/b079/411aa110-67a6-4cda-9606-e3473f1bb079/FallFuryPart5_220.jpg" height="124" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/b079/411aa110-67a6-4cda-9606-e3473f1bb079/FallFuryPart5_512.jpg" height="289" width="512"></media:thumbnail>      
      <dc:creator>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</dc:creator>
      <itunes:author>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-5-Creating-Levels/RSS</wfw:commentRss>
      <category>C#</category>
      <category>C++</category>
      <category>DirectX</category>
      <category>Windows Store App</category>
    </item>
  <item>
      <title>Fall Fury: Part 4 - XAML Interop</title>
      <description><![CDATA[<p>As mentioned earlier in the series, FallFury does not solely rely on DirectX to display content to the user. As a Windows Store game, FallFury leverages the new <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh825871.aspx">Direct2D (XAML) project template</a>, available in Visual Studio 2012.&nbsp; Check out the video for this article at <a href="http://channel9.msdn.com/Series/FallFury/Part-4-XAML-Interop">http://channel9.msdn.com/Series/FallFury/Part-4-XAML-Interop</a>.&nbsp; For a complete, offline version of this series, you may <a href="http://media.ch9.ms/coding4fun/fallfury/FallFury.pdf">download a nicely formatted PDF of all the articles</a>.</p><h4>The Concept of a Swap Chain</h4><p>Before I go into detail about the DirectX and XAML interop in FallFury, I want to cover one important aspect of DirectX development that you need to familiarize yourself with: the swap chain.</p><p>When your graphics adapter draws on the visual surface, you, as the user, see only minor potential redraws. Internally, however, the device switches buffers that reflect the displayed content, with each buffer representing a frame that has to be drawn. You can deduce from this that any swap chain has at least two buffers that it can switch between.</p><p>For example, if I want to display my character as being displaced by a specific amount of pixels, the buffer will at the outset present to me the character in its initial position, while the second buffer will be constructed in the background with the proper position adjustments. The first frame, made from the content from the first buffer, will be discarded, and then the second frame will be displayed, and so on. This process occurs at a very high speed that depends on the processing capabilities of the graphics adapter, so the user does not notice the swapping itself.</p><p>The most common swap chain is composed of two buffers—the screenbuffer and the secondary framebuffer.</p><h4>SwapChainBackgroundPanel</h4><p>DirectX interoperability with XAML simplifies a lot of routine tasks that would otherwise be handled with manual rendering procedures, such as a menu system or a simple game HUD. That being said, the way the XAML workflow is organized in a Direct2D project is <a href="http://msdn.microsoft.com/en-US/library/windows/apps/hh825871">quite different</a> compared to a standard XAML Windows Store or Windows Phone application.</p><p>The core difference is that there is no navigational system per-se and the fundamental entity in a Direct2D (XAML) project that manages the XAML content is a <a href="http://msdn.microsoft.com/library/windows/apps/Hh702626">SwapChainBackgroundPanel</a> control. This control allows the developer to overlay XAML elements on top of the DirectX renders. It replaces the normal page-based layout with one in which it is sole container for every XAML control that has to be used in the application. This necessitates that you will have to organize the secondary elements in such a way that the correct set is displayed for the current application state.</p><p>For example, if the user is in the main menu, menu options as well as the game logo should be shown. When the user switches to the game mode, the HUD should appear and the menu should become hidden. Although both the menu and the HUD are a part of the same SwapChainBackgroundPanel, I will have to manually manage state and visibility changes.</p><p>Using the SwapChainBackgroundPanel also means that you will have to enforce specific graphic configuration rules in your application. One of them applies to setting up the swap chain. When you set up the scaling, it must be set to <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh404526(v=vs.85).aspx">DXGI_SCALING_STRETCH</a>:</p><p><pre class="brush: cpp">
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
swapChainDesc.Width = static_cast&lt;UINT&gt;(m_renderTargetSize.Width); 
swapChainDesc.Height = static_cast&lt;UINT&gt;(m_renderTargetSize.Height);
swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
swapChainDesc.Stereo = false; 
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferCount = 2;
swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
swapChainDesc.Flags = 0;
</pre></p><p>&nbsp;</p><p>The swap chain itself should be configured for composition, mixing the native DirectX buffer with the overlaid XAML. This is done by calling <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh404558(v=vs.85).aspx">CreateSwapChainForComposition</a>:</p><p><pre class="brush: cpp">
ThrowIfFailed(
    dxgiFactory-&gt;CreateSwapChainForComposition(
        m_d3dDevice.Get(),
        &amp;swapChainDesc,
        nullptr,
        &amp;m_swapChain
        )
    );

ComPtr&lt;ISwapChainBackgroundPanelNative&gt; panelNative;
ThrowIfFailed(
    reinterpret_cast&lt;IUnknown*&gt;(m_panel)-&gt;QueryInterface(IID_PPV_ARGS(&amp;panelNative))
    );

ThrowIfFailed(
    panelNative-&gt;SetSwapChain(m_swapChain.Get())
    );
</pre></p><p>There really isn’t much additional configuration work beyond this point. Remember, that the XAML content will <strong>always be overlaid on top of the DirectX content</strong>; therefore, plan the game components accordingly.</p><h4>The XAML Menu System</h4><p>The menu is at the core of the FallFury experience. When designing it, I was inspired by how Dance Central built the user interaction mechanism, and I tried to implement a similar approach in which the user would have to slide the button to the right instead of simply tapping on it:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image002%5B3%5D-4.jpg"><img title="clip_image002" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image002_thumb-5.jpg" alt="clip_image002" width="624" height="317" border="0"></a></p><p>Each menu item is built around a custom <strong>MenuItem</strong> control (<strong>MenuItem.xaml</strong>):</p><p><pre class="brush: xml">
&lt;UserControl
    x:Class=&quot;Coding4Fun.FallFury.MenuItem&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:local=&quot;using:Coding4Fun.FallFury&quot;
    xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
    xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
    mc:Ignorable=&quot;d&quot;
    x:Name=&quot;menuItem&quot;
    Margin=&quot;10, 0, 0, 10&quot;&gt;

    &lt;Grid 
        Height=&quot;65&quot; 
        ManipulationMode=&quot;TranslateX&quot;
        ManipulationCompleted=&quot;Grid_ManipulationCompleted&quot;
        ManipulationDelta=&quot;Grid_ManipulationDelta&quot; 
        x:Name=&quot;ControlContainer&quot;
        PointerPressed=&quot;Grid_PointerPressed&quot; 
        PointerReleased=&quot;Grid_PointerReleased&quot;&gt;
        
        &lt;Grid.Resources&gt;
            &lt;Storyboard x:Name=&quot;ArrowAnimator&quot;&gt;
                &lt;DoubleAnimation Storyboard.TargetName=&quot;ImageTranslateTransform&quot;
                                 Storyboard.TargetProperty=&quot;X&quot;
                                 From=&quot;0&quot;
                                 To=&quot;20&quot;
                                 Duration=&quot;0:0:0.4&quot;
                                 RepeatBehavior=&quot;Forever&quot;
                                 AutoReverse=&quot;True&quot;&gt;
                &lt;/DoubleAnimation&gt;
            &lt;/Storyboard&gt;

        &lt;/Grid.Resources&gt;
        
        &lt;Grid.RowDefinitions&gt;
            &lt;RowDefinition Height=&quot;10&quot; /&gt;
            &lt;RowDefinition /&gt;
            &lt;RowDefinition /&gt;
            &lt;RowDefinition Height=&quot;10&quot; /&gt;
        &lt;/Grid.RowDefinitions&gt;
        &lt;Grid.ColumnDefinitions&gt;
            &lt;ColumnDefinition Width=&quot;10&quot; /&gt;
            &lt;ColumnDefinition /&gt;
        &lt;/Grid.ColumnDefinitions&gt;
        &lt;StackPanel Orientation=&quot;Horizontal&quot; Grid.RowSpan=&quot;4&quot; Grid.ColumnSpan=&quot;4&quot;&gt;
            &lt;!-- width is sent in code behind, have to get this dynamic ...  --&gt;
            &lt;Grid Width=&quot;350&quot; x:Name=&quot;coverRectangle&quot;&gt;
                &lt;Rectangle Fill=&quot;#303030&quot; /&gt;
                &lt;Rectangle 
                    Fill=&quot;Red&quot; 
                    x:Name=&quot;coverActiveRectangle&quot; /&gt;
            &lt;/Grid&gt;
            &lt;Image x:Name=&quot;MenuImage&quot; Source=&quot;ms-appx:///MenuItems/single_arrow.png&quot; Margin=&quot;10,0,0,0&quot; Stretch=&quot;Uniform&quot;&gt;
                &lt;Image.RenderTransform&gt;
                    &lt;TranslateTransform x:Name=&quot;ImageTranslateTransform&quot;&gt;&lt;/TranslateTransform&gt;
                &lt;/Image.RenderTransform&gt;
            &lt;/Image&gt;
        &lt;/StackPanel&gt;
        &lt;!----&gt;

        &lt;TextBlock 
            Text=&quot;{Binding ElementName=menuItem, RelativeSource={RelativeSource Self}, Path=Label}&quot;
            Grid.RowSpan=&quot;4&quot;
            Grid.ColumnSpan=&quot;4&quot;
            Style=&quot;{StaticResource MenuItemText}&quot;&gt;

        &lt;/TextBlock&gt;
        
        &lt;MediaElement x:Name=&quot;coreMenuMedia&quot; Source=&quot;ms-appx:///Assets/Sounds/MenuTap.wav&quot; AutoPlay=&quot;False&quot;&gt;&lt;/MediaElement&gt;
        &lt;MediaElement x:Name=&quot;slideMenuMedia&quot; Source=&quot;ms-appx:///Assets/Sounds/MenuSlide.wav&quot; AutoPlay=&quot;False&quot;&gt;&lt;/MediaElement&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;
</pre></p><p>There is a core storyboard that is used to perform an image bounce. Initial tests showed that that most users tend to follow the standard “click-and-go” pattern and even though the implemented button was a slider, they tried to click it at least once, expecting the game to take them to the next screen. To avoid this, I introduced a visual arrow indicator that bounces left and right to indicate the direction of the necessary slide.</p><p>When the sliding occurs, the overlay grid width is being adjusted relative to the manipulation. At the same time, the button changes from passive state (dark background):</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image003%5B3%5D.png"><img title="clip_image003" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image003_thumb.png" alt="clip_image003" width="423" height="75" border="0"></a></p><p>to active state (red background):</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image004%5B3%5D.png"><img title="clip_image004" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image004_thumb.png" alt="clip_image004" width="465" height="76" border="0"></a></p><p>Internally, the double-arrow image replaces the single-arrow one and is translated across the X-axis to create a bouncing effect:</p><p><pre class="brush: cpp">
void MenuItem::Grid_PointerPressed(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
    BitmapImage^ image = ref new BitmapImage(ref new Uri(&quot;ms-appx:///MenuItems/double_arrow.png&quot;));
    MenuImage-&gt;Source = image;
    
    coverActiveRectangle-&gt;Visibility = Windows::UI::Xaml::Visibility::Visible;
    ((Storyboard^)ControlContainer-&gt;Resources-&gt;Lookup(&quot;ArrowAnimator&quot;))-&gt;Begin();
    
    coreMenuMedia-&gt;Play();
}
</pre></p><p>As the user drags the finger on the button, the red overlay size should be adjusted accordingly. The size adjustment can be easily tracked in the ManipulationDelta event handler for the focused grid:</p><p><pre class="brush: cpp">
void MenuItem::Grid_ManipulationDelta(Platform::Object^ sender, Windows::UI::Xaml::Input::ManipulationDeltaRoutedEventArgs^ e)
{
    double diff = e-&gt;Cumulative.Translation.X;
    
    if (diff &gt; maxDeltaSize)
    {
        diff = maxDeltaSize;
    }
    else if (diff &lt; 0)
    {
        diff = 0;
    }
    
    coverRectangle-&gt;Width = initialBarWidth &#43; diff;
}
</pre></p><p>When the user action on the button is completed, the ManipulationCompleted event handler is triggered on the same overlay grid. If the relative drag hits the critical threshold, the action linked to the button should be invoked:</p><p><pre class="brush: cpp">
void MenuItem::Grid_ManipulationCompleted(Platform::Object^ sender, Windows::UI::Xaml::Input::ManipulationCompletedRoutedEventArgs^ e)
{
    float diff = e-&gt;Cumulative.Translation.X;
    
    if (diff &gt; maxDeltaSize - 50) // slight buffer
    {
        slideMenuMedia-&gt;Play();
        OnButtonSelected(this, Label);
    }
    
    ResetElements();
}
</pre></p><p>There are also local sound effects that are played when the slider-button is tapped and moved to the end. Both are handled by separate <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.mediaelement">MediaElement</a> controls that avoid an internal sound file switch, calling instead the <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.mediaelement.play">Play</a> method as necessary. The <strong>OnButtonSelected</strong> event handler can be dynamically hooked in the application backend.</p><p>Each button also has a visible content area that can display a text label. It can be set through a DependencyProperty:</p><p><pre class="brush: cpp">
DependencyProperty^ MenuItem::_LabelProperty = 
    DependencyProperty::Register(&quot;Label&quot;, 
    Platform::String::typeid,
    MenuItem::typeid, 
    nullptr);
</pre></p><p>In its current configuration, the menu label can be also set in XAML:</p><p><pre class="brush: xml">
&lt;local:MenuItem x:Name=&quot;btnNewGame&quot; Label=&quot;new game&quot;&gt;
    &lt;local:MenuItem.RenderTransform&gt;
        &lt;TranslateTransform&gt;&lt;/TranslateTransform&gt;
    &lt;/local:MenuItem.RenderTransform&gt;
&lt;/local:MenuItem&gt;
</pre></p><p>When the button loses the focus, the state resets to the passive one, stopping the animation and resetting the arrow image to the single one:</p><p><pre class="brush: cpp">
void MenuItem::ResetElements()
{
    BitmapImage^ image = ref new BitmapImage(ref new Uri(&quot;ms-appx:///MenuItems/single_arrow.png&quot;));
    MenuImage-&gt;Source = image;
    
    ((Storyboard^)ControlContainer-&gt;Resources-&gt;Lookup(&quot;ArrowAnimator&quot;))-&gt;Stop();
    
    coverRectangle-&gt;Width = initialBarWidth;
    coverActiveRectangle-&gt;Visibility = Windows::UI::Xaml::Visibility::Collapsed;
}
</pre></p><p>That’s about as complex as the menu item control will get. The menu container itself can be any <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.grid">Grid</a> or <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.stackpanel">StackPanel</a> control. The way the menu items are used across the game states, there is no need to have a separate unified container.</p><h4>The Main XAML Container &amp; State Changes</h4><p>Going back to <strong>DirectXPage.xaml</strong>, there are several parts of the XAML layout that should be highlighted. First and foremost, the game curtains—the static parts of the screen that are being displayed instead of blacking out parts of the viewport that are not being used when the game runs in landscape mode. Because the game includes a rectangular frame instead of stretching the entire playable area to the size of the screen, there is an unknown amount of unallocated visual space on both the right and left sides of the frame itself:</p><p><pre class="brush: xml">
&lt;Grid HorizontalAlignment=&quot;Left&quot; x:Name=&quot;containerA&quot;&gt;
    &lt;Rectangle Fill=&quot;#09bbe3&quot; /&gt;

    &lt;Rectangle Width=&quot;10&quot; HorizontalAlignment=&quot;Left&quot;&gt;
        &lt;Rectangle.Fill&gt;
            &lt;LinearGradientBrush StartPoint=&quot;0,0&quot; EndPoint=&quot;1,0&quot;&gt;
                &lt;GradientStop Color=&quot;#a000&quot; Offset=&quot;0.0&quot;&gt;&lt;/GradientStop&gt;
                &lt;GradientStop Color=&quot;#0000&quot; Offset=&quot;1.0&quot;&gt;&lt;/GradientStop&gt;
            &lt;/LinearGradientBrush&gt;
        &lt;/Rectangle.Fill&gt;
    &lt;/Rectangle&gt;
&lt;/Grid&gt;

&lt;Grid HorizontalAlignment=&quot;Right&quot; x:Name=&quot;containerB&quot;&gt;
    &lt;Rectangle Fill=&quot;#09bbe3&quot; /&gt;

    &lt;Rectangle Width=&quot;10&quot; HorizontalAlignment=&quot;Right&quot;&gt;
        &lt;Rectangle.Fill&gt;
            &lt;LinearGradientBrush StartPoint=&quot;1,0&quot; EndPoint=&quot;0,0&quot;&gt;
                &lt;GradientStop Color=&quot;#a000&quot; Offset=&quot;0.0&quot;&gt;&lt;/GradientStop&gt;
                &lt;GradientStop Color=&quot;#0000&quot; Offset=&quot;1.0&quot;&gt;&lt;/GradientStop&gt;
            &lt;/LinearGradientBrush&gt;
        &lt;/Rectangle.Fill&gt;
    &lt;/Rectangle&gt;
&lt;/Grid&gt;
</pre></p><p>Although these two grids have set alignments, the actual location on the screen will be set in code-behind because the size will also be re-calculated. Also, I need to make sure that the application is in the full display mode—if it is snapped, there is no need to display the curtains because the visible area will be reduced to an overlay grid.</p><p>The curtain resize and visibility are determined in the UpdateWindowSize method:</p><p><pre class="brush: cpp">
void DirectXPage::UpdateWindowSize()
{
    bool visibility = true;
    if (ApplicationView::Value == ApplicationViewState::Snapped)
            visibility = false;
    
    float margin = (m_renderer-&gt;m_renderTargetSize.Width - 768.0f) / 2.0f;
    if (margin &lt; 2.0)
            visibility = false;
    
    if (visibility)
    {
        containerA-&gt;Width =  margin;
        containerA-&gt;HorizontalAlignment = Windows::UI::Xaml::HorizontalAlignment::Right;
        containerB-&gt;Width =  margin;
        containerB-&gt;HorizontalAlignment = Windows::UI::Xaml::HorizontalAlignment::Left;
        containerA-&gt;Visibility = Windows::UI::Xaml::Visibility::Visible;
        containerB-&gt;Visibility = Windows::UI::Xaml::Visibility::Visible;
    }
    else
    {
        containerA-&gt;Visibility = Windows::UI::Xaml::Visibility::Collapsed;
        containerB-&gt;Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    }
}
</pre></p><p>The snippet above ensures that the curtains will only be displayed when there is extra, unused space in addition to the 768 pixels taken by the playable area.</p><p>Let’s take a look at state-specific content that is being displayed whenever the game switches states. Because of the nature of DirectX interaction, there is no way for me to hook to specific event handlers from the native loop. Therefore, I need to constantly check that the content displayed is associated with the current state.</p><p>This can be done with the help of the <strong>SwitchGameState</strong> method:</p><p><pre class="brush: cpp">
void DirectXPage::SwitchGameState()
{
    switch (m_renderer-&gt;CurrentGameState)
            {
            case GameState::GS_FULL_WIN:
                    {
                            grdCompleteWin-&gt;Visibility = Windows::UI::Xaml::Visibility::Visible;
                            break;
                    }
            case GameState::GS_PLAYING:
                    {
                            Hud-&gt;Visibility = Windows::UI::Xaml::Visibility::Visible;
                            break;
                    }
            case GameState::GS_MAIN_MENU:
                    {
                            stkMainMenu-&gt;Visibility = Windows::UI::Xaml::Visibility::Visible;
                            break;
                    }
            case GameState::GS_GAME_OVER:
                    {
                            UpdateResults();
                            ResultPanel-&gt;Visibility = Windows::UI::Xaml::Visibility::Visible;
                            grdGameOver-&gt;Visibility = Windows::UI::Xaml::Visibility::Visible;
                            break;
                    }
            case GameState::GS_SUBMIT_SCORE:
                    {
                            grdSubmitScore-&gt;Visibility = Windows::UI::Xaml::Visibility::Visible;
                            txtSubmitScoreView-&gt;Text = StaticDataHelper::Score.ToString();
                            break;
                    }
            case GameState::GS_TOP_SCORES:
                    {
                            grdTopScores-&gt;Visibility = Windows::UI::Xaml::Visibility::Visible;
                            break;
                    }
            case GameState::GS_WIN:
                    {
                            UpdateResults();
                            grdWinner-&gt;Visibility = Windows::UI::Xaml::Visibility::Visible;
                            ResultPanel-&gt;Visibility = Windows::UI::Xaml::Visibility::Visible;
                            break;
                    }
            case GameState::GS_ABOUT_SCREEN:
                    {
                            grdAbout-&gt;Visibility =  Windows::UI::Xaml::Visibility::Visible;
                            break;
                    }
            case GameState::GS_LEVEL_SELECT_SINGLE:
                    {
                            animationBeginTime = 0;
            
                            stkLevelSelector-&gt;Visibility = Windows::UI::Xaml::Visibility::Visible;
                            break;
                    }
            case GameState::GS_HOW_TO:
                    {
                            grdHowTo-&gt;Visibility = Windows::UI::Xaml::Visibility::Visible;
                            Storyboard^ howToInitialBoard = (Storyboard^)grdMain-&gt;Resources-&gt;Lookup(&quot;StoryboardChainA&quot;);
                            howToInitialBoard-&gt;Begin();
                            break;
                    }
        default:
                    break;
            }
    
            Storyboard^ loc = (Storyboard^)grdMain-&gt;Resources-&gt;Lookup(&quot;FadingOut&quot;);
            loc-&gt;Begin();
}
</pre></p><p>One thing you’ve probably noticed about the snippet above is the fact that there is no indicator showing that controls are being hidden when the state changes. Just calling <strong>SwitchGameState</strong> in the Update loop would cause multiple controls to be displayed at once. However, there is also the <strong>HideEverything</strong> method that goes through the visual tree and sets the <strong>Visibility</strong> to <strong>Collapsed</strong> for everything:</p><p><pre class="brush: cpp">
void DirectXPage::HideEverything()
{
    for (uint i = 0; i &lt; grdMain-&gt;Children-&gt;Size; i&#43;&#43;)
    {
        grdMain-&gt;Children-&gt;GetAt(i)-&gt;Visibility = Windows::UI::Xaml::Visibility::Collapsed;
    }
}
</pre></p><p>&nbsp;</p><h4>HUD Interaction</h4><p>The Heads-Up Display (HUD) is used to alert the player about the current state of the game and the game character. In FallFury, it is used to display three indicators: how many buttons the character collected, how much time it took the character to get to the current level part, and current character health. It is also the container for the Pause button.</p><p>Here is the visual representation:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image006%5B3%5D.jpg"><img title="clip_image006" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image006_thumb-1.jpg" alt="clip_image006" width="517" height="331" border="0"></a></p><p>Here is the underlying XAML:</p><p><pre class="brush: xml">
&lt;Grid x:Name=&quot;Hud&quot; VerticalAlignment=&quot;Top&quot; Visibility=&quot;Collapsed&quot;&gt;
    &lt;Grid.RowDefinitions&gt;
        &lt;RowDefinition Height=&quot;80&quot; /&gt;
        &lt;RowDefinition Height=&quot;Auto&quot; /&gt;
    &lt;/Grid.RowDefinitions&gt;
    &lt;Grid.ColumnDefinitions&gt;
        &lt;ColumnDefinition /&gt;
        &lt;ColumnDefinition /&gt;
        &lt;ColumnDefinition /&gt;
        &lt;ColumnDefinition Width=&quot;80&quot; /&gt;
    &lt;/Grid.ColumnDefinitions&gt;

    &lt;Rectangle Fill=&quot;Black&quot; Grid.ColumnSpan=&quot;4&quot; /&gt;

    &lt;Button
        Grid.Column=&quot;0&quot;
        x:Name=&quot;btnPause&quot;
        Click=&quot;btnPause_Click&quot;
        Style=&quot;{StaticResource PauseButton}&quot;&gt;
        &lt;Image Source=&quot;ms-appx:///Assets/HUD/pauseButton.png&quot; Stretch=&quot;None&quot; /
    &lt;/Button&gt;

    &lt;StackPanel Grid.Column=&quot;1&quot; Orientation=&quot;Horizontal&quot;&gt;
        &lt;Image Source=&quot;ms-appx:///Assets/HUD/buttonHud.png&quot; Stretch=&quot;None&quot; /&gt;

        &lt;TextBlock
            x:Name=&quot;txtButtons&quot;
            Text=&quot;0&quot;
            Style=&quot;{StaticResource hudResult}&quot;/&gt;
    &lt;/StackPanel&gt;

    &lt;StackPanel Grid.Column=&quot;2&quot; Orientation=&quot;Horizontal&quot;&gt;
        &lt;Image Source=&quot;ms-appx:///Assets/HUD/clockHud.png&quot; Stretch=&quot;None&quot; /&gt;

        &lt;TextBlock
            x:Name=&quot;txtTimer&quot;
            Text=&quot;00:00&quot;
            Style=&quot;{StaticResource hudResult}&quot;/&gt;
    &lt;/StackPanel&gt;

    &lt;Image
        Grid.Column=&quot;3&quot;
        Source=&quot;ms-appx:///Assets/HUD/heartHud.png&quot;
        Stretch=&quot;None&quot; /&gt;

    &lt;Grid
        Grid.Column=&quot;3&quot;
        Grid.Row=&quot;1&quot;&gt;
        &lt;Rectangle Fill=&quot;Black&quot; Opacity=&quot;.8&quot;/&gt;
        &lt;controls:HealthBar x:Name=&quot;healthBar&quot;&gt;&lt;/controls:HealthBar&gt;
    &lt;/Grid&gt;
&lt;/Grid&gt;
</pre></p><p>As I mentioned before, the DirectX layer cannot directly interact with the XAML layer. Therefore, there needs to be an intermediary binding class. As the game progress changes, the <strong>UpdateHUD</strong> method is called, taking a reference to the current DirectX screen and reading the game data from the character and the <strong>StaticDataHelper</strong> class, which is the container for the time elapsed:</p><p><pre class="brush: cpp">
void DirectXPage::UpdateHud(GamePlayScreen^ playScreen)
{
    healthBar-&gt;Update(playScreen-&gt;GameBear-&gt;CurrentHealth, playScreen-&gt;GameBear-&gt;MaxHealth);
    
    txtButtons-&gt;Text = StaticDataHelper::ButtonsCollected.ToString();
    
    // Find a better built-in string formatting code
    if (m_renderer-&gt;CurrentGameState == GameState::GS_PLAYING &amp;&amp; !(StaticDataHelper::IsPaused) &amp;&amp; playScreen-&gt;IsLevelLoaded)
    {
        StaticDataHelper::SecondsTotal &#43;= m_timer-&gt;Delta;
        
        txtTimer-&gt;Text = StaticDataHelper::GetTimeString((int)StaticDataHelper::SecondsTotal);
    }
}
</pre></p><p>As seen above, part of the HUD is taken by a health indicator control—<strong>HealthBar</strong>. It is a simple composite element made out of two overlaying rectangles, one of which is resized as the bear health changes:</p><p><pre class="brush: xml">
&lt;UserControl
    x:Class=&quot;Coding4Fun.FallFury.Controls.HealthBar&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:local=&quot;using:FallFury&quot;
    xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
    xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
    mc:Ignorable=&quot;d&quot;
    d:DesignHeight=&quot;410&quot;
    d:DesignWidth=&quot;20&quot; Height=&quot;410&quot; Width=&quot;20&quot;&gt;
    
    &lt;Grid&gt;
        &lt;StackPanel VerticalAlignment=&quot;Top&quot; Margin=&quot;0, 5, 0,20&quot;&gt;
            &lt;Rectangle Height=&quot;400&quot; Style=&quot;{StaticResource HealthRectangle}&quot; /&gt;
        &lt;/StackPanel&gt;

        &lt;StackPanel VerticalAlignment=&quot;Top&quot; Margin=&quot;0, 5, 0, 10&quot;&gt;
            &lt;Rectangle x:Name=&quot;OverlayStacker&quot; Height=&quot;0&quot; Style=&quot;{StaticResource HealthOverlayRectangle}&quot; /&gt;
        &lt;/StackPanel&gt;
    &lt;/Grid&gt;
&lt;/UserControl&gt;
</pre></p><p>Being of a fixed size, it is fairly easy to calculate the health-to-damage ratio and display that as the size of the overlaid rectangle:</p><p><pre class="brush: cpp">
DependencyProperty^ HealthBar::_MaxHealthProperty = 
    DependencyProperty::Register(&quot;MaxHealth&quot;, 
    double::typeid,
    HealthBar::typeid, 
    nullptr);

DependencyProperty^ HealthBar::_CurrentHealthProperty = 
    DependencyProperty::Register(&quot;CurrentHealth&quot;, 
    double::typeid,
    HealthBar::typeid, 
    nullptr);

void HealthBar::Update(double currentHealth, double maxHealth)
{
    CurrentHealth = currentHealth;
    MaxHealth = maxHealth;
    
    if (CurrentHealth &gt;= 0)
    {
        OverlayStacker-&gt;Height = 400.0 - ((400.0 * CurrentHealth) / MaxHealth);
    }
}
</pre></p><h4>Conclusion</h4><p>Using XAML as a part of a DirectX application does not require the developer to do a massive overhaul of the infrastructure. That said, be mindful when deciding whether to use a hybrid XAML application, as it is much easier to integrate a SwapChainBackgroundPanel with the underlying DirectX configuration from the ground up instead of trying to do so when the DirectX component is completed.</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:f25dcd4fcbea4abdab11a1400002dab2">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-4-XAML-Interop</comments>
      <itunes:summary>As mentioned earlier in the series, FallFury does not solely rely on DirectX to display content to the user. As a Windows Store game, FallFury leverages the new Direct2D (XAML) project template, available in Visual Studio 2012.&amp;nbsp; Check out the video for this article at http://channel9.msdn.com/Series/FallFury/Part-4-XAML-Interop.&amp;nbsp; For a complete, offline version of this series, you may download a nicely formatted PDF of all the articles. The Concept of a Swap ChainBefore I go into detail about the DirectX and XAML interop in FallFury, I want to cover one important aspect of DirectX development that you need to familiarize yourself with: the swap chain. When your graphics adapter draws on the visual surface, you, as the user, see only minor potential redraws. Internally, however, the device switches buffers that reflect the displayed content, with each buffer representing a frame that has to be drawn. You can deduce from this that any swap chain has at least two buffers that it can switch between. For example, if I want to display my character as being displaced by a specific amount of pixels, the buffer will at the outset present to me the character in its initial position, while the second buffer will be constructed in the background with the proper position adjustments. The first frame, made from the content from the first buffer, will be discarded, and then the second frame will be displayed, and so on. This process occurs at a very high speed that depends on the processing capabilities of the graphics adapter, so the user does not notice the swapping itself. The most common swap chain is composed of two buffers—the screenbuffer and the secondary framebuffer. SwapChainBackgroundPanelDirectX interoperability with XAML simplifies a lot of routine tasks that would otherwise be handled with manual rendering procedures, such as a menu system or a simple game HUD. That being said, the way the XAML workflow is organized in a Direct2D project is quite different </itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-4-XAML-Interop</link>
      <pubDate>Wed, 23 Jan 2013 23:57:07 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-4-XAML-Interop</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/04e6/01086880-1f2d-4b77-8261-a7ccc0c804e6/FallFuryPart4_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/04e6/01086880-1f2d-4b77-8261-a7ccc0c804e6/FallFuryPart4_220.jpg" height="124" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/04e6/01086880-1f2d-4b77-8261-a7ccc0c804e6/FallFuryPart4_512.jpg" height="289" width="512"></media:thumbnail>      
      <dc:creator>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</dc:creator>
      <itunes:author>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-4-XAML-Interop/RSS</wfw:commentRss>
      <category>C#</category>
      <category>C++</category>
      <category>DirectX</category>
      <category>Windows Store App</category>
    </item>
  <item>
      <title>Fall Fury: Part 3 - Basic Rendering and Movement</title>
      <description><![CDATA[<p>Continuing the FallFury series, in this article I talk about basic game element rendering and character movement. As you already know, the FallFury user experience stack is split across two layers—native DirectX and XAML. Here, I will only be talking about the native DirectX component.&nbsp; Check out the video for this article at <a href="http://channel9.msdn.com/Series/FallFury/Part-3-Basic-Rendering-and-Movement">http://channel9.msdn.com/Series/FallFury/Part-3-Basic-Rendering-and-Movement</a>&nbsp; For a complete, offline version of this series, you may <a href="http://media.ch9.ms/coding4fun/fallfury/FallFury.pdf">download a nicely formatted PDF of all the articles</a>.</p><h4>The Background</h4><p>Each game screen in FallFury has a moving background that creates the illusion of a fall. The way the screen is designed, it simulates vertical <a href="http://en.wikipedia.org/wiki/Parallax_scrolling">parallax scrolling</a>, as the background moves faster than the overlaid objects. There is a simple way to make background movement possible without actually having to replicate parts of the texture and render them all over again. Take a look at this image, showcasing the process:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B2%5D-6.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb-7.png" alt="image" width="610" height="480" border="0"></a></p><p>First of all, two textures are loaded that, connected at the bottom, create the illusion of a single texture. In the beginning, texture A takes the entire screen and texture B is positioned directly underneath it, with a non-existing gap between them. To initiate the scrolling, texture A is being displaced vertically by an arbitrary number of pixels, and texture B follows it at the same pace. As texture B reaches the zero point (top of the viewport), texture A is no longer visible, therefore it is displaced vertically to be below texture B. This cycle can be repeated as many times as necessary during gameplay as well as while the user is in the menu.</p><p>Let’s take a look at the code that makes it possible, starting with the main menu screen:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B5%5D-8.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B1%5D-5.png" alt="image" width="623" height="354" border="0"></a></p><p>First of all, you need to be aware that every game screen is automatically inheriting the properties and capabilities of base class <strong>GameScreenBase</strong>. This is the class the offers the foundation both for basic texture loading and movement:</p><p><pre class="brush: cpp">
protected private:
    // Core background textures
    Microsoft::WRL::ComPtr&lt;ID3D11Texture2D&gt;                    m_backgroundBlockA;
    Microsoft::WRL::ComPtr&lt;ID3D11Texture2D&gt;                    m_backgroundBlockB;

void MoveBackground(float velocity);
</pre></p><p>It also offers the core texture containers for the overlaid elements that are present in most screens, such as clouds:</p><p><pre class="brush: cpp">
// Overlayed clouds
Microsoft::WRL::ComPtr&lt;ID3D11Texture2D&gt; m_overlayA;
Microsoft::WRL::ComPtr&lt;ID3D11Texture2D&gt; m_overlayB;
</pre></p><p>The overlay movement is inherently dependent on the base background displacement and can be adjusted relative to the initial velocity. Let’s take a look at <strong>GameScreenBase.cpp</strong>, specifically at <strong>MoveBackground</strong>:</p><p><pre class="brush: cpp">
void GameScreenBase::MoveBackground(float velocity)
{
    if (m_backgroundPositionA &lt;= -BACKGROUND_MIDPOINT)
        m_backgroundPositionA = m_backgroundPositionB &#43; (BACKGROUND_MIDPOINT * 2);

    if (m_backgroundPositionB &lt;= -BACKGROUND_MIDPOINT)
        m_backgroundPositionB = m_backgroundPositionA &#43; (BACKGROUND_MIDPOINT * 2);

    m_backgroundPositionA -= velocity;
    m_backgroundPositionB -= velocity;
}
</pre></p><p>The BACKGROUND_MIDPOINT value is relative to the height of the background texture. As we are working with a variable screen size, given that tablets and desktops do not have the same resolution, the movement has to be adjusted accordingly. One way, however, to ensure the proper texture positioning would be to place it in relation to its previous instance. Hence, this snippet in <strong>UpdateWindowSize</strong>:</p><p><pre class="brush: cpp">
BACKGROUND_MIDPOINT = 1366.0f / 2.0f;
m_backgroundPositionA = BACKGROUND_MIDPOINT;
m_backgroundPositionB = m_backgroundPositionA * 3;
</pre></p><p>Because overlays are not necessarily a part of every screen, I am not including the <strong>MoveOverlay</strong> method in the base class. Let’s now take a look at <strong>MenuScreen.cpp</strong>. Take a look at the Load method and you will see several lines that prepare the background and overlays:</p><p><pre class="brush: cpp">
m_loader = ref new BasicLoader(Manager-&gt;m_d3dDevice.Get(), Manager-&gt;m_wicFactory.Get());

m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\generic_blue_a.png&quot;, &amp;m_backgroundBlockA, nullptr);
m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\generic_blue_b.png&quot;, &amp;m_backgroundBlockB, nullptr);
m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\cloud_overlay_a.png&quot;, &amp;m_overlayA, nullptr);
m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\cloud_overlay_b.png&quot;, &amp;m_overlayB, nullptr);

CurrentSpriteBatch-&gt;AddTexture(m_backgroundBlockA.Get());
CurrentSpriteBatch-&gt;AddTexture(m_backgroundBlockB.Get());
CurrentSpriteBatch-&gt;AddTexture(m_overlayA.Get());
CurrentSpriteBatch-&gt;AddTexture(m_overlayB.Get());
</pre></p><p>The <strong>BasicLoader</strong> class was imported from the <a href="http://code.msdn.microsoft.com/windowsapps/Direct3D-sprite-sample-97ae6262">Direct3D sprite sample</a>. A call to LoadTexture will read the data from a DDS or PNG file and output the data in an <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ff476635%28v=vs.85%29.aspx">ID3D11Texture2D</a> object. Once loaded, the texture is added to the <strong>SpriteBatch</strong> instance associated with the screen, also declared as a part of <strong>GameScreenBase</strong>.</p><p>Depending on the screen, this procedure might have to be done for multiple textures, as you will see later in this article. Each page also has two timed loops—<strong>RenderScreen</strong> and <strong>Update</strong>. RenderScreen is responsible for taking everything from the SpriteBatch instance and showing it to the user. If you’ve used the <a href="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.spritebatch.aspx">XNA SpriteBatch</a> before, you are aware that you need to start the drawing cycle by calling <strong>Begin</strong> and end it by calling <strong>End</strong>. The same applies here:</p><p><pre class="brush: cpp">
CurrentSpriteBatch-&gt;Begin();

CurrentSpriteBatch-&gt;Draw(
    m_backgroundBlockA.Get(),
    float2(Manager-&gt;m_windowBounds.Width / 2, m_backgroundPositionA),
    PositionUnits::DIPs,
    m_screenSize,
    SizeUnits::Pixels);

CurrentSpriteBatch-&gt;Draw(
    m_backgroundBlockB.Get(),
    float2(Manager-&gt;m_windowBounds.Width / 2 ,m_backgroundPositionB),
    PositionUnits::DIPs,
    m_screenSize,
    SizeUnits::Pixels);

if (m_showBear-&gt;IsLoaded)
    m_showBear-&gt;Render();

if (m_showMonster-&gt;IsLoaded)
    m_showMonster-&gt;Render();

CurrentSpriteBatch-&gt;Draw(
    m_overlayA.Get(),
    float2(Manager-&gt;m_windowBounds.Width/2, m_backgroundPositionA),
    PositionUnits::DIPs,
    m_screenSize,
    SizeUnits::Pixels);

CurrentSpriteBatch-&gt;Draw(
    m_overlayB.Get(),
    float2(Manager-&gt;m_windowBounds.Width / 2 ,m_backgroundPositionB),
    PositionUnits::DIPs,
    m_screenSize,
    SizeUnits::Pixels);

CurrentSpriteBatch-&gt;End();
</pre></p><p>The current overloaded <strong>Draw</strong> call gets the following items:</p><ul><li>The texture object </li><li>The position where the object has to be drawn on the screen </li><li>The way the object is positioned (can also be a normalized value or a pixel value) </li><li>The size of the texture (stretching may occur) </li><li>The type of the size value (in this case, I am using pixels, but can also be normalized) </li></ul><p>The order in which the <strong>Draw</strong> calls are arranged determines the order of objects drawn on the screen. The calls on top will place texture objects at the bottom of the rendering stack, and the calls at the end will place the objects at the top of the stack.</p><h4>The Gameplay Screen Background &amp; Overlays</h4><p>Let’s move on to the arguably most critical screen in the project, <strong>GamePlayScreen.cpp</strong>. There are a few nuances that differentiate it from any other screen—in particular, the background loading routine.</p><p>For every game, there is a different level type that is being used. With each level type, there is a different combination of a background and the overlay. Currently, there are four supported level types:</p><ul><li>Space </li><li>Nightmare </li><li>Magic Bean </li><li>Dream </li></ul><p>When the proper level is detected and the metadata is loaded from the associated XML file (more about this process later on in the series), the level textures are loaded into memory:</p><p><pre class="brush: cpp">
switch (m_currentLevelType)
{
    case LevelType::SPACE:
    {
        m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\generic_dark_blue_a.png&quot;, &amp;m_backgroundBlockA, nullptr);
        m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\generic_dark_blue_b.png&quot;, &amp;m_backgroundBlockB, nullptr);
        m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\star_overlay_a.png&quot;, &amp;m_overlayA, nullptr);
        m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\star_overlay_b.png&quot;, &amp;m_overlayB, nullptr);
        m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\galaxy_overlay_a.png&quot;, &amp;m_overlayGalaxyA, nullptr);
        m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\galaxy_overlay_b.png&quot;, &amp;m_overlayGalaxyB, nullptr);
        
        CurrentSpriteBatch-&gt;AddTexture(m_overlayGalaxyA.Get());
        CurrentSpriteBatch-&gt;AddTexture(m_overlayGalaxyB.Get());
        break;
    }
    case LevelType::NIGHTMARE:
    {
        m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\generic_red_a.png&quot;, &amp;m_backgroundBlockA, nullptr);
        m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\generic_red_b.png&quot;, &amp;m_backgroundBlockB, nullptr);
        m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\cloud_overlay_a.png&quot;, &amp;m_overlayA, nullptr);
        m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\cloud_overlay_b.png&quot;, &amp;m_overlayB, nullptr);
        break;
    }
    case LevelType::MAGIC_BEANS:
    {
        m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\generic_blue_a.png&quot;, &amp;m_backgroundBlockA, nullptr);
        m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\generic_blue_b.png&quot;, &amp;m_backgroundBlockB, nullptr);
        m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\cloud_overlay_a.png&quot;, &amp;m_overlayA, nullptr);
        m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\cloud_overlay_b.png&quot;, &amp;m_overlayB, nullptr);
        
        break;
    }
    case LevelType::DREAM:
    {
        m_loader-&gt;LoadTexture(&quot;DDS\\Levels\\Dream\\TEST_backgroundDream_01.dds&quot;, &amp;m_backgroundBlockA, nullptr);
        m_loader-&gt;LoadTexture(&quot;DDS\\Levels\\Dream\\TEST_backgroundDream_02.dds&quot;, &amp;m_backgroundBlockB, nullptr);
        m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\cloud_overlay_a.png&quot;, &amp;m_overlayA, nullptr);
        m_loader-&gt;LoadTexture(&quot;Assets\\Backgrounds\\cloud_overlay_b.png&quot;, &amp;m_overlayB, nullptr);
        break;
    }
}
</pre></p><p>This way, no unnecessary textures are loaded. A screen-based level flag allows me to control the incoming assets. At this point, the level environment does not change dynamically, so it is safe to assume that the textures should be loaded on a per-level basis.</p><p>The RenderScreen method is called in the same manner as in the menu screen, with the moving background and overlays located at the bottom of the rendering stack:</p><p><pre class="brush: cpp">
CurrentSpriteBatch-&gt;Draw(
    m_backgroundBlockA.Get(),
    float2(Manager-&gt;m_windowBounds.Width / 2, m_backgroundPositionA),
    PositionUnits::DIPs,
    m_screenSize,
    SizeUnits::Pixels);

CurrentSpriteBatch-&gt;Draw(
    m_backgroundBlockB.Get(),
    float2(Manager-&gt;m_windowBounds.Width / 2, m_backgroundPositionB),
    PositionUnits::DIPs,
    m_screenSize,
    SizeUnits::Pixels);

CurrentSpriteBatch-&gt;Draw(
    m_overlayA.Get(),
    float2(Manager-&gt;m_windowBounds.Width / 2, m_overlayPositionA),
    PositionUnits::DIPs,
    float2(768.0f, 1366.0f),
    SizeUnits::Pixels);

CurrentSpriteBatch-&gt;Draw(
    m_overlayB.Get(),
    float2(Manager-&gt;m_windowBounds.Width / 2, m_overlayPositionB),
    PositionUnits::DIPs,
    float2(768.0f, 1366.0f),
    SizeUnits::Pixels);
</pre></p><h4>Character Movement</h4><p>As you are now aware of the basic screen structure and how the basic rendering process is built, let’s take a look at how the main game character moves on the screen. Falling down, the teddy bear also needs to move left and right to ensure that he is able to pick up power-ups and buttons as well as avoid obstacles and enemy ammo.</p><p>There are several important considerations here. The most important one is to not assume that the user will have a specific input device. Potential movement controllers include a keyboard, the mouse, the touch screen and the accelerometer. In the most common scenarios, the desktop machines will not have an accelerometer, and the tablet computers will not have a constantly attached keyboard and a mouse. In FallFury, I decided to leverage all potential input engines and let the user choose the best option for himself.</p><p>When the current GamePlayScreen instance loads, I am attempting to get access to the system accelerometer device:</p><p><pre class="brush: cpp">
m_systemAccelerometer = Windows::Devices::Sensors::Accelerometer::GetDefault();
</pre></p><p><strong>m_systemAccelerometer</strong> is of type <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.sensors.accelerometer">Windows::Devices::Sensors::Accelerometer</a> and is declared in <strong>GamePlayScreen.h</strong>. If an accelerometer is detected, I need to bind it to a <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.sensors.accelerometer.readingchanged">ReadingChanged</a> event handler that will give me the current G-force transformed into X, Y, and Z displacement:</p><p><pre class="brush: cpp">
if (m_systemAccelerometer != nullptr)
{
    m_systemAccelerometer-&gt;ReadingChanged &#43;= ref new TypedEventHandler&lt;Accelerometer^, AccelerometerReadingChangedEventArgs^&gt;
            (this, &amp;GamePlayScreen::AccelerometerReadingChanged);
}
</pre></p><p><strong>ReadingChanged</strong> itself does not participate in updating the position for the character, but rather passes the current values to <strong>m_xAcceleration</strong>, which is later used in the <strong>Update</strong> method:</p><p><pre class="brush: cpp">
void GamePlayScreen::AccelerometerReadingChanged(_In_ Accelerometer^ accelerometer, _In_ AccelerometerReadingChangedEventArgs^ args)
{
    if (StaticDataHelper::IsAccelerometerEnabled)
    {
        auto currentOrientation = DisplayProperties::CurrentOrientation;
        float accelValue;
        
        if (currentOrientation == DisplayOrientations::Portrait)
                    accelValue = args-&gt;Reading-&gt;AccelerationY;
        else if (currentOrientation == DisplayOrientations::PortraitFlipped)
                    accelValue = -args-&gt;Reading-&gt;AccelerationY;
        else if (currentOrientation == DisplayOrientations::Landscape)
                    accelValue = args-&gt;Reading-&gt;AccelerationX;
        else if (currentOrientation == DisplayOrientations::LandscapeFlipped)
                    accelValue = -args-&gt;Reading-&gt;AccelerationX;
        else
                    accelValue = 0.0f;
        
        if (StaticDataHelper::IsAccelerometerInverted)
                    m_xAcceleration = -accelValue;
        else
                    m_xAcceleration = accelValue;
    }
}
</pre></p><p>The reason for this lies in the fact that <strong>ReadingChanged</strong> is triggered at a much lower rate than the <strong>Update</strong> loop. If the character position would be adjusted through the core accelerometer event handler, the result would be choppy (“step-by-step”) movement instead of a smooth transition.</p><p>Notice, also, that depending on the screen orientation, I need to get the acceleration either on the X- or Y-axes. Since an accelerometer is detected, I am assuming that the device that’s being used is a tablet. Therefore, it can have auto-rotate enabled, which means that the reference axis (horizontal) might change depending on how the user holds the device. <a href="http://msdn.microsoft.com/en-US/library/windowsphone/develop/windows.graphics.display.displayproperties.currentorientation.aspx">DisplayProperties::CurrentOrientation</a> can give me the current orientation, whether portrait (Y acceleration value) or landscape (X acceleration value):</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B8%5D-3.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B2%5D-7.png" alt="image" width="622" height="349" border="0"></a></p><p>As with many other titles, the user may invert the movement based on the accelerometer reading. For example, if the device is tilted to the right, the character will move to the left, and vice-versa. The effect is easily achieved by negating the current reading, regardless of the axis it is relying on.</p><p>Obviously, as the character moves, there should be boundaries that restrict the movement within the context of the current game screen. To get the correct screen bounds, <strong>GameScreenBase</strong>, the foundation class for every screen, sets four properties: <strong>LoBoundX</strong>, <strong>HiBoundX</strong>, <strong>LoBoundY</strong> and <strong>HiBoundY</strong>:</p><p><pre class="brush: cpp">
LoBoundX = (rWidth - 768.0f) / 2.0f;
HiBoundX = LoBoundX &#43; 768.0f;

LoBoundY = 0;
HiBoundY = LoBoundY &#43; rHeight;
</pre></p><p><strong>LoBoundX</strong> is the leftmost limit for the horizontal playable area and <strong>HiBoundX</strong> is the rightmost limit for the same horizontal area. <strong>LoBoundY</strong> and <strong>HiBoundY</strong> are responsible for carrying the limits for the vertical space. All four boundary values are relative to the screen size:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image%5B11%5D-2.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/image_thumb%5B3%5D-7.png" alt="image" width="624" height="355" border="0"></a></p><p>To consistently get the correct X boundary no matter the screen size, the playable area is set to a fixed width of 768 pixels. The rest of the screen is accordingly cancelled out and the remaining area split in two. The original X point (zero) is added to the curtain size and that way there is the leftmost X boundary. The Y boundaries are simply obtained from the screen height, as there are no gameplay experience restrictions in that domain.</p><p>The bear position is updated in the Update loop in the game screen. There are several parameters that need to be adjusted, such as the vertical velocity, the bear rotation on tilt and the horizontal displacement.</p><p>When the level just starts, the bear falls faster until he reaches the standard static Y point. Because of screen size differences, this should not be done by comparing the pixel distance but rather by utilizing a ratio built from the current bear Y position and the high Y boundary:</p><p><pre class="brush: cpp">
if ((GameBear-&gt;Position.y / HiBoundY) &lt; 0.19f)
{
    GameBear-&gt;Position.y &#43;= GameBear-&gt;Velocity.y * (3.2f);
}
</pre></p><p>Assuming that the game is not paused, and thus the background is moving, the bear Y position should be adjusted relative to the current velocity set for the background scrolling. Because of how parallax scrolling works, the bear velocity has to be higher than the initial screen movement. Therefore, it is multiplied by a fixed value independent of the level played:</p><p><pre class="brush: cpp">
if (!m_isBackgroundMoving)
{
    if (GameBear-&gt;Position.y &gt; m_screenSize.y)
    {
        Manager-&gt;CurrentGameState = GameState::GS_GAME_OVER;
    }
    else
    {
        GameBear-&gt;Position.y &#43;= GameBear-&gt;Velocity.y * 1.5f;
    }
}
</pre></p><p>In the statement above, there is also an extra condition that verifies whether the bear is below the low Y boundary. If it is, then the game is over. This is imposed by a game animation that takes the bear off the Y limits, meaning that the bear is dead.</p><p>Bear rotation is based on the current X acceleration, but the bear shouldn’t rotate 360 degrees. To limit the rotation, there is a rotation threshold set (value taken in radians) that is being checked before rotating the character:</p><p><pre class="brush: cpp">
float compositeRotation = GameBear-&gt;Rotation - (float)m_xAcceleration / 10.0f;
if (compositeRotation &lt; m_rotationThreshold &amp;&amp; compositeRotation &gt; -m_rotationThreshold)
    GameBear-&gt;Rotation = compositeRotation;
</pre></p><p>The composite value lets me verify the perspective rotation without actually assigning it to the bear. If it is within the imposed threshold, only then will the bear rotation be adjusted.</p><p>Using the composite value approach is also efficient when performing the horizontal displacement adjustment. The initial value is composed of the current position and the X-based acceleration multiplied by a dynamic multiplier value to create the inertia effect:</p><p><pre class="brush: cpp">
float compositePosition = GameBear-&gt;Position.x &#43; ((float)m_xAcceleration * m_accelerationMultiplier);

if (m_xAcceleration &lt; 0)
    compositePosition -= 100.0f;
else
    compositePosition &#43;= 100.0f;

if (Manager-&gt;IsWithinScreenBoundaries(float2(compositePosition, GameBear-&gt;Position.y)))
{
    GameBear-&gt;Position.x &#43;= (float)m_xAcceleration * m_accelerationMultiplier;
}
else
{
    if (GameBear-&gt;Position.x &gt; HiBoundX)
    {
        GameBear-&gt;Position.x = HiBoundX - 180.0f;
    }
    else if (GameBear-&gt;Position.x &lt; LoBoundX)
    {
        GameBear-&gt;Position.x = LoBoundX &#43; 180.0f;
    }
}
</pre></p><p>If the bear is attempting to hit a “wall” (screen limit), its position is set back to the one barely prior to the limit. By doing this, I am avoiding locking the character on the side of the screen.</p><p>There is something in this snippet above that you might not be aware of—a reference to <strong>Manager-&gt;IsWithinScreenBoundaries</strong>. This method belongs to the ScreenManager (ScreenManager.cpp) class—a utility class that ensures the proper screen is displayed depending on the current game mode, and also allows control of mouse actions and boundary checks:</p><p><pre class="brush: cpp">
bool ScreenManager::IsWithinScreenBoundaries(float2 position)
{
    if (position.x &lt; CurrentGameScreen-&gt;LoBoundX || position.x &gt; CurrentGameScreen-&gt;HiBoundX || position.y &lt; CurrentGameScreen-&gt;LoBoundY || position.y &gt; CurrentGameScreen-&gt;HiBoundY)
            return false;
    else
            return true;
}
</pre></p><p>You saw how the movement is accomplished with the help of the accelerometer. Let’s take a look at how a keyboard can be used to do the same thing. There is a <strong>HandleKeyInput</strong> method, exposed through the <strong>GamePlayScreen</strong> class. As a matter of fact, <strong>HandleKeyInput</strong> is wired into the <strong>GameScreenBase</strong> class, therefore if a specific combination needs to be handled outside the context of the game play screen, it can be:</p><p><pre class="brush: cpp">
void GamePlayScreen::HandleKeyInput(Windows::System::VirtualKey key)
{
    if (key == Windows::System::VirtualKey::Right)
    {
        if (GameBear-&gt;IsWithinScreenBoundaries(GameBear-&gt;Size.x, 0.0f, GetScreenBounds()))
        {
            GameBear-&gt;Direction = TurningState::RIGHT;
            
            m_xAcceleration = 0.8f;
            
            if (GameBear-&gt;Rotation &gt;= -m_rotationThreshold)
                            GameBear-&gt;Rotation -= 0.02f;
        }
    }
    else if (key == Windows::System::VirtualKey::Left)
    {
        if (GameBear-&gt;IsWithinScreenBoundaries(-GameBear-&gt;Size.x, 0.0f, GetScreenBounds()))
        {
            GameBear-&gt;Direction = TurningState::LEFT;
            
            m_xAcceleration = -0.8f;
            
            if (GameBear-&gt;Rotation &lt;= m_rotationThreshold)
                            GameBear-&gt;Rotation &#43;= 0.02f;
        }
    }
}
</pre></p><p>As the accelerometer is no longer influencing the rotation or displacement, both indicators have to be manipulated through key presses. There are still standard thresholds in place to limit the potential incorrect movement, but the idea remains the same. This method is being called from the XAML page, which is overlaid on top of the DirectX renders:</p><p><pre class="brush: xml">
&lt;SwapChainBackgroundPanel
    x:Class=&quot;Coding4Fun.FallFury.DirectXPage&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:local=&quot;using:Coding4Fun.FallFury&quot; x:Name=&quot;XAMLPage&quot;
    xmlns:controls=&quot;using:Coding4Fun.FallFury.Controls&quot;
    xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
    xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
    mc:Ignorable=&quot;d&quot; Loaded=&quot;OnLoaded&quot; KeyDown=&quot;OnKeyDown&quot; LayoutUpdated=&quot;XAMLPage_LayoutUpdated&quot;&gt;
</pre><pre class="brush: cpp">
void DirectXPage::OnKeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e)
{
    m_renderer-&gt;CurrentGameScreen-&gt;HandleKeyInput(e-&gt;Key);
}
</pre></p><p>When the keyboard is not available, movement can be controlled with the help of a mouse. Again, with standard event handlers, I am simply using <strong>OnPointerMoved</strong>:</p><p><pre class="brush: cpp">
void GamePlayScreen::OnPointerMoved(Windows::UI::Core::PointerEventArgs^ args)
{
    if (StaticDataHelper::IsMouseEnabled)
    {
        if (GameBear != nullptr)
        {
            m_touchCounter&#43;&#43;;
            if (GameBear-&gt;IsWithinScreenBoundaries(GameBear-&gt;Size.x, 0.0f, GetScreenBounds()))
            {
                m_xAcceleration = (args-&gt;CurrentPoint-&gt;RawPosition.X - GameBear-&gt;Position.x) / m_screenSize.x;
            }
        }
    }
}
</pre></p><p>By using this method, the bear will accelerate to the point where the mouse cursor is located, having a higher velocity the further it is located from the cursor. Once again, this creates the inertia visualization.</p><h4>Conclusion</h4><p>Concluding Part 3 of the series, remember that because Windows 8 is not a tablet-only OS, some users might have different input devices. Try to accommodate as many of those as possible.</p><p>The next article in this series will focus on the XAML overlay used in FallFury.</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:4c48bfe7230449a1af4ca13f017fd4e4">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-3-Basic-Rendering-and-Movement</comments>
      <itunes:summary>Continuing the FallFury series, in this article I talk about basic game element rendering and character movement. As you already know, the FallFury user experience stack is split across two layers—native DirectX and XAML. Here, I will only be talking about the native DirectX component.&amp;nbsp; Check out the video for this article at http://channel9.msdn.com/Series/FallFury/Part-3-Basic-Rendering-and-Movement&amp;nbsp; For a complete, offline version of this series, you may download a nicely formatted PDF of all the articles. The BackgroundEach game screen in FallFury has a moving background that creates the illusion of a fall. The way the screen is designed, it simulates vertical parallax scrolling, as the background moves faster than the overlaid objects. There is a simple way to make background movement possible without actually having to replicate parts of the texture and render them all over again. Take a look at this image, showcasing the process:  First of all, two textures are loaded that, connected at the bottom, create the illusion of a single texture. In the beginning, texture A takes the entire screen and texture B is positioned directly underneath it, with a non-existing gap between them. To initiate the scrolling, texture A is being displaced vertically by an arbitrary number of pixels, and texture B follows it at the same pace. As texture B reaches the zero point (top of the viewport), texture A is no longer visible, therefore it is displaced vertically to be below texture B. This cycle can be repeated as many times as necessary during gameplay as well as while the user is in the menu. Let’s take a look at the code that makes it possible, starting with the main menu screen:  First of all, you need to be aware that every game screen is automatically inheriting the properties and capabilities of base class GameScreenBase. This is the class the offers the foundation both for basic texture loading and movement: 
protected private:
    // Core background textur</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-3-Basic-Rendering-and-Movement</link>
      <pubDate>Wed, 23 Jan 2013 23:57:03 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-3-Basic-Rendering-and-Movement</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/f2a1/9afdc0cb-6045-4e66-97d6-89d9297bf2a1/FallFuryPart3_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/f2a1/9afdc0cb-6045-4e66-97d6-89d9297bf2a1/FallFuryPart3_220.jpg" height="124" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/f2a1/9afdc0cb-6045-4e66-97d6-89d9297bf2a1/FallFuryPart3_512.jpg" height="289" width="512"></media:thumbnail>      
      <dc:creator>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</dc:creator>
      <itunes:author>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</itunes:author>
      <slash:comments>0</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-3-Basic-Rendering-and-Movement/RSS</wfw:commentRss>
      <category>C#</category>
      <category>C++</category>
      <category>DirectX</category>
      <category>Windows Store App</category>
    </item>
  <item>
      <title>Fall Fury: Part 2 - Shaders</title>
      <description><![CDATA[<h4>Introduction to Shaders</h4><p>FallFury not only relies on standard C&#43;&#43;/C# and XAML code, but also on shaders. This article is intended for developers who are not aware of what shaders are and want to know how to use them in their projects. I will talk about creating shaders, as well as the shaders used in my project.</p><p>Check out the video for this article at <a href="http://channel9.msdn.com/Series/FallFury/Part-2-Shaders">http://channel9.msdn.com/Series/FallFury/Part-2-Shaders</a>.&nbsp; For a complete, offline version of this series, you may <a href="http://media.ch9.ms/coding4fun/fallfury/FallFury.pdf">download a nicely formatted PDF of all the articles</a>.</p><h4>Code on GPU</h4><p>In simple terms, shaders are small programs that are executed on the Graphical Processing Unit (GPU) instead of the Central Processing Unit (CPU). In recent years, we’ve seen a major spike in the capabilities of graphic devices, allowing hardware manufacturers to design an execution layer tied to the GPU, therefore being able to target device-specific manipulations to a highly optimized unit. Shaders are not used for simple calculations, but rather for image processing. For example, a shader can be used to adjust image lighting or colors.</p><p>Modern GPUs give access to the rendering pipeline that allows developers to execute arbitrary image processing code. This is a step forward from a fixed-function pipeline that was present in older GPUs, where image processing tasks were integrated into the hardware unit and were only able to perform a limited set of actions, such as transforms. Unlike the rendering pipeline, the fixed-function pipeline was not programmable, therefore the developers were often tied to the hardware they used for offering specific game effects, in some cases having to resort to software-based adjustments.</p><h4>Types of Shaders</h4><p>There are different types of image manipulations that can be performed on a given input, and so there are different types of shaders designed to handle that. Currently, we can highlight three main shader types:</p><ul><li><strong>Vertex shaders</strong> – because what the user sees on the screen is not really three-dimensional, but rather a three-dimensional simulation in a 2D space, vertex shaders translate the coordinates of a vector in 3D space in relation to the 2D frame. Vertex shaders are executed one time per vector passed to the GPU. Typically, vectors carry data related to their position and the coordinate of the bound texture as well as color. A vertex shader is able to manipulate all these properties, but there is never a situation where a new vertex is created as a result of the execution. </li><li><strong>Pixel shaders</strong> – these programs are executed on the GPU in relation to every passed pixel, working on a much lower level. For example, if you want specific pixels adjusted for lighting or 3D bump mapping, a pixel shader can provide the desired effect for a surface. Rarely, there are situations where only a few pixels should be re-adjusted at once. Pixel shaders are often run with an input of millions of pixels, resulting in complex effects. </li><li><strong>Geometry shaders</strong> – these shaders are the next progression from vertex shaders, introduced with DirectX 10. The developer is able to pass specific primitives as input and either have the output represent the modified version of what was passed to the program or have new primitives, such as triangles, be generated as a result. Geometry shaders are always executed on post-vertex processing in the rendering pipeline. When vertex shader execution is completed, geometry shaders step in, if present. Geometry shaders can be used to refine the level of detail of a specific object. For example, when an object is closer or further away from the viewport camera, the mesh would have to be refined to minimize the rendering load. </li></ul><p>FallFury uses all these shader types as a part of the game.</p><h4>Enough Talk, Let’s Code</h4><p>Now that you are aware of what shaders are, let’s write some sample code and test it. It is worth mentioning that shaders are not written in a standard high-level language, but rather in a language defined by the environment the shader is used in. For Direct3D, this is the High-Level Shader Language, or HLSL. It is somewhat similar to C, but with some specific nuances.</p><p>Start by creating a test Direct3D Windows Store application:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image002%5B3%5D-3.jpg"><img title="clip_image002" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image002_thumb-4.jpg" alt="clip_image002" width="624" height="380" border="0"></a></p><p>If you create and run this sample application, you will see that the output of it is a simple 3D spinning cube:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image004%5B3%5D-2.jpg"><img title="clip_image004" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image004_thumb-3.jpg" alt="clip_image004" width="435" height="243" border="0"></a></p><p>You probably also noticed that there are two shaders that are a component part of the newly created solution: <strong>SimplePixelShader.hlsl</strong> and <strong>SimpleVertexShader.hlsl</strong>. Take a look inside the pixel shader:</p><p><pre class="brush: cpp">
struct PixelShaderInput
{
    float4 pos : SV_POSITION;
    float3 color : COLOR0;
};

float4 main(PixelShaderInput input) : SV_TARGET
{
    return float4(input.color,1.0f);
}
</pre></p><p>First of all, there is a PixelShaderInput <a>struct</a><a name="_msoanchor_1"></a>[DW1] . It represents a single pixel – it has a float4 field that represents the position of the pixel and a float3 field that represents the RGB pixel color. The field itself is also marked by a predefined type, such as SV_POSITION or COLOR. This is a string that determines the use of the field. You can read more about the shader semantics <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb509647(v=vs.85).aspx">here</a>.</p><p>The strings that are prefixed with SV_ are representing system-value semantics. Those have special meaning in the pipeline during the processing stages. In the pixel shader above, SV_POSITION will always mean the pixel position.</p><p>Look at what is being returned from the pixel shader—instead of the standard float3 color indicator, you are now returning a float4, which couples the existing value, input.color, with a 1.0f float value that represents the alpha-channel value. Remember, that inside shaders the color is clamped between 0 and 1 instead of the standard 255-value limit.</p><p>Since the cube rendering mechanism is already in place, let’s experiment with the pixel shader a bit. You’ve already got the float4 color representation:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image006%5B3%5D.png"><img title="clip_image006" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image006_thumb.png" alt="clip_image006" width="580" height="157" border="0"></a></p><p>You can set any of these values to 1.0 to return the solid color, so let’s do that. Let’s render the cube green. Modify the return statement to be this:</p><p>return float4(0.0, 1.0, 0.0, 1.0);</p><p>At this point, if you will run the program you will get a rendering very similar to this:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image008%5B3%5D-1.jpg"><img title="clip_image008" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image008_thumb-2.jpg" alt="clip_image008" width="624" height="346" border="0"></a></p><p>This is a good start.. Now, let’s now take a look at the vertex shader in the project. By default, you get this:</p><p><pre class="brush: cpp">
cbuffer ModelViewProjectionConstantBuffer : register(b0)
{
    matrix model;
    matrix view;
    matrix projection;
};

struct VertexShaderInput
{
    float3 pos : POSITION;
    float3 color : COLOR0;
};

struct VertexShaderOutput
{
    float4 pos : SV_POSITION;
    float3 color : COLOR0;
};

VertexShaderOutput main(VertexShaderInput input)
{
    VertexShaderOutput output;
    float4 pos = float4(input.pos, 1.0f);
    
    pos = mul(pos, model);
    pos = mul(pos, view);
    pos = mul(pos, projection);
    output.pos = pos;
    
    // Pass through the color without modification.
    output.color = input.color;
    
    return output;
}
</pre></p><p>There are a couple of differences here compared to the above mentioned pixel shader:</p><ul><li><strong>cbuffer ModelViewProjectionConstantBuffer</strong> – represents a constant buffer that contains three matrices, to which vertices are related—the model, view and projection matrices. Constant buffers are interesting structures that have been optimized to allow block-wise updates, where multiple constants are grouped in one boxed unit and can be updated simultaneously instead of having a one-by-one iterative update cycle. </li><li><strong>struct VertexShaderInput</strong> – vertices are passed one-by-one to the shader, and this specific structure represents the input. Notice that it carries the 3D representation of the vertex position as well as its RGB color value. </li><li><strong>struct VertexShaderOutput </strong>– the final processed output, which now carries the position in relation to all three matrices mentioned above as well as the processed color. Notice that the fourth value is the camera distance in the demo. </li><li><strong>VertexShaderOutput main(VertexShaderInput input) </strong>– this is the main function that performs the vertex processing. Initially, it performs the position adjustment relative to the camera and then uses <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb509628(v=vs.85).aspx">mul</a>, a built-in function that multiplies matrices, to represent the current vertices in the projected space. </li></ul><p>So let’s play around with what we have in stock. Take a look at the main function and how initially, the float3-based position is transformed to contain the camera distance:</p><p><pre class="brush: cpp">
float4 pos = float4(input.pos, 1.0f);
</pre></p><p>This position is normalized in relation to the current viewport. Afterwards, the vertex is transformed in the current 3D space (relative to three matrices – model, view, and projection):</p><p><pre class="brush: cpp">
pos = mul(pos, model);
pos = mul(pos, view);

pos = mul(pos, projection);

output.pos = pos;
</pre></p><p>As with the pixel shader, these are some very basic manipulations. Let’s flip the cube upside-down. To do this, we need to apply a rotation transformation. Here is an interesting piece of advice—when working with manipulations in shaders, make sure that you know basic matrix operations.</p><p>For example, to perform a simple 2D rotation, you need to use the <a href="http://en.wikipedia.org/wiki/Rotation_matrix">rotation matrix</a>:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image009%5B3%5D.png"><img title="clip_image009" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image009_thumb.png" alt="clip_image009" width="169" height="48" border="0"></a></p><p>But since we’re in 3D space, we not only have the X and Y coordinates, which relate to the matrix above, but also the Z coordinate. Therefore, a different method should be applied. There are three fundamental matrices that can be used to rotate an object around the three possible axes:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image011%5B3%5D.png"><img title="clip_image011" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image011_thumb.png" alt="clip_image011" width="236" height="285" border="0"></a></p><p>For now, we want to rotate the cube along the X-axis. To do this, inside the main function, we need to declare a constant that represents the rotation angle, in radians:</p><p><pre class="brush: cpp">
const float angle = 1.3962634;
</pre></p><p>Looking at the matrix above, we need to find out the sine and cosine of the given angle. When working with vertex shaders, HLSL offers a built-in function, called <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb147382(v=vs.85).aspx">sincos</a> that is able to get both values from an input value:</p><p><pre class="brush: cpp">
float cosLength, sinLength;
sincos(angle, sinLength, cosLength);
</pre></p><p>Now you need to declare the rotation matrix. Again, HLSL comes with some built-in capabilities to declare matrices and set their values:</p><p><pre class="brush: cpp">
float3x3 xAxisRotation = { 
    1.0, 0.0, 0.0, // Row 1
    0, cosLength, -sinLength, // Row 2
    0, sinLength, cosLength}; // Row 3
</pre></p><p>&nbsp;</p><p>The standard format for matrix declaration in this case follows the following pattern:</p><p>Matrix&lt;type,size&gt; localName</p><p>For matrix multiplication, we can once again leverage the mul function:</p><p><pre class="brush: cpp">
float3 temporaryPosition;
temporaryPosition = mul(input.pos,xAxisRotation);
</pre></p><p>Now we can normalize the position to a float4 value that also includes the camera distance:</p><p><pre class="brush: cpp">
float4 pos = float4(temporaryPosition, 1.0f);
</pre></p><p>The rest of the transformation procedures can be taken directly from the original shader, multiplying the float4 position by the model, view, and projection matrices. Your entire main function should now look like this:</p><p><pre class="brush: cpp">
VertexShaderOutput main(VertexShaderInput input)
{
    VertexShaderOutput output;

    const float angle = 1.3962634;
    float cosLength, sinLength;
    sincos(angle, sinLength, cosLength);

    float3x3 xAxisRotation = { 
        1.0, 0.0, 0.0, // Row 1
        0, cosLength, -sinLength, // Row 2
        0, sinLength, cosLength}; // Row 3

    float3 temporaryPosition;
    temporaryPosition = mul(input.pos,xAxisRotation);
    float4 pos = float4(temporaryPosition, 1.0f);

    // Transform the vertex position into projected space.
    pos = mul(pos, model);
    pos = mul(pos, view);
    pos = mul(pos, projection);
    output.pos = pos;

    // Pass through the color without modification.
    output.color = input.color;

    return output;
}
</pre></p><p>The current angle is set to 80 degrees, or 1.3962634 radians. If you run the rendering test application, the result you will get will be similar to this:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image013%5B3%5D.jpg"><img title="clip_image013" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image013_thumb.jpg" alt="clip_image013" width="449" height="252" border="0"></a></p><p>Now, let’s look at how shaders are handled on the DirectX side.</p><h4>Shaders in DirectX</h4><p>Open <strong>CubeRenderer.cpp</strong>. This is the source file where internal shaders are read and passed to the device to be executed. Notice one interesting aspect of the process – the shader file contents are being read first and then passed to <strong>m_d3dDevice-&gt;CreateVertexShader</strong>. m_d3dDevice is a pointer to a virtual adapter that can be used to create device-specific resources. <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ff476524(v=vs.85).aspx">CreateVertexShader</a> creates a vertex shader from an already compiled shader. You can notice it from the fact that the data is read not from the initial <strong>.hlsl</strong> file, but rather from the <strong>.cso (Compiled Shader Object)</strong>:</p><p>auto loadVSTask = DX::ReadDataAsync(&quot;SimpleVertexShader.cso&quot;);</p><p>As with any program, before it is passed onto the execution layer, it has to be compiled first. Visual Studio 2012 comes with a bundled HLSL compiler, <strong>fxc</strong>—the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb232919(v=vs.85).aspx">Effect Compiler Tool</a>. The default behavior for a shader is to be compiled with the .cso file extension in the same output directory as the project, but this can be changed by setting the <strong>Object File Name</strong> in the shader properties:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image015%5B3%5D.jpg"><img title="clip_image015" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image015_thumb.jpg" alt="clip_image015" width="624" height="443" border="0"></a></p><p>You can read more about the shader compilation process <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb509633(v=vs.85).aspx">here</a>.</p><p>Looking back at the sample vertex shader that was created as a part of the project, you will notice that there is a specific input layout set for the incoming object:</p><p><pre class="brush: cpp">
struct VertexShaderInput
{
    float3 pos : POSITION;
    float3 color : COLOR0;
};
</pre></p><p>&nbsp;</p><p>The virtual adapter is not aware of the structure layout. Therefore, the developer needs to explicitly create an internal <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ff476180(v=vs.85).aspx">D3D11_INPUT_ELEMENT_DESC</a> array that will contain the type of information passed to the shader:</p><p><pre class="brush: cpp">
const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = 
{
    { 
        &quot;POSITION&quot;, 
        0, 
        DXGI_FORMAT_R32G32B32_FLOAT, 
        0, 
        0, 
        D3D11_INPUT_PER_VERTEX_DATA, 
        0 },
    {
        &quot;COLOR&quot;, 
        0, 
        DXGI_FORMAT_R32G32B32_FLOAT, 
        0, 
        12, 
        D3D11_INPUT_PER_VERTEX_DATA, 
        0 },
};
</pre></p><p>&nbsp;</p><p>Once the description is complete, the input needs to be assembled for processing. That’s where <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ff476512%28v=vs.85%29.aspx">CreateInputLayout</a> comes into play:</p><p><pre class="brush: cpp">
DX::ThrowIfFailed(
    m_d3dDevice-&gt;CreateInputLayout(
        vertexDesc,
        ARRAYSIZE(vertexDesc),
        fileData-&gt;Data,
        fileData-&gt;Length,
        &amp;m_inputLayout
        )
    );
</pre></p><p>&nbsp;</p><p>You are basically passing a shader signature to the input assembler that will perform all the consequent processing. A similar process is applied for the existing pixel shader, with the main difference being the fact that instead of CreateVertexShader, <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ff476513%28v=vs.85%29.aspx">CreatePixelShader</a> is called:</p><h4>Passing Custom Parameters to Shaders</h4><p>Going back to our vertex shader where we performed the rotation relative to the X-axis, you probably noticed that the angle is hard-coded and is applied to each vector in the same way. This is rarely the case, as the angle would normally come from inside the game itself, often responding to internal behavior, such as character movement or action.</p><p>To pass a parameter to the shader, you need to first of all redefine the input structure. Let’s add an angle carrier to the <strong>VertexShaderInput</strong> struct in <strong>SimpleVertexShader.hlsl</strong>:</p><p><pre class="brush: cpp">
struct VertexShaderInput
{
    float3 pos : POSITION;
    float3 color : COLOR0;
    float angle : TRANSFORM0;
};
</pre></p><p>This alone won’t do anything. Go the entry point function (<strong>main</strong>) and make sure that the angle constant is set to <strong>input.angle</strong>:</p><p><pre class="brush: cpp">
const float angle = input.angle;
</pre></p><p>Now the shader is ready, but you also need to let your game know that the vertex shader has a modified input layout. To do this, go to <strong>CubeRenderer.cpp</strong> and find the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ff476180%28v=vs.85%29.aspx">D3D11_INPUT_ELEMENT_DESC</a> array that defines the input layout for incoming vertex shaders. Simply add an identifying item to the existing array:</p><p><pre class="brush: cpp">
const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = 
{ 
    { &quot;POSITION&quot;, 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, 
    { &quot;COLOR&quot;, 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, 
    { &quot;TRANSFORM&quot;, 0, DXGI_FORMAT_R32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 } 
};
</pre></p><p>The first parameter is the pre-defined semantic used in the shader. The second parameter defines the input index. After that, use <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb173059%28v=vs.85%29.aspx">DXGI_FORMAT_R32_FLOAT</a> to indicate that the value passed will be a standard float. Pay close attention when you specify the input offset. Notice that the two FLOAT3 values, POSITION and COLOR, take 12 bytes each —a float takes 32 bits (4 bytes), and you have a triplet, therefore the offset for TRANSFORM should be 24 bytes (two times 12 bytes from previous indicators).</p><p>Now you need to modify the internal vector descriptors that are being passed to the rendering pipe. In the sample project those are created with the help of the VertexPositionColor class, located in the <strong>CubeRenderer.h</strong>. Add a simple float field to the existing struct, so it looks like this:</p><p><pre class="brush: cpp">
struct VertexPositionColor 
{ 
    DirectX::XMFLOAT3 pos; 
    DirectX::XMFLOAT3 color; 
    float angle; 
};
</pre></p><p>&nbsp;</p><p>In <strong>CubeRenderer.cpp</strong>, find the <strong>cubeVerticles</strong> array. For each created <strong>VertexPositionColor</strong> you are now able to add a third value representing the rotation:</p><p><pre class="brush: cpp">
auto createCubeTask = (createPSTask &amp;&amp; createVSTask).then([this] () { 
    VertexPositionColor cubeVertices[] = 
    { 
        {XMFLOAT3(-0.5f, -0.5f, -0.5f), XMFLOAT3(0.0f, 0.0f, 0.0f), 1.38f}, 
        {XMFLOAT3(-0.5f, -0.5f, 0.5f), XMFLOAT3(0.0f, 0.0f, 1.0f), 1.38f}, 
        {XMFLOAT3(-0.5f, 0.5f, -0.5f), XMFLOAT3(0.0f, 1.0f, 0.0f), 1.38f}, 
        {XMFLOAT3(-0.5f, 0.5f, 0.5f), XMFLOAT3(0.0f, 1.0f, 1.0f), 1.38f}, 
        {XMFLOAT3( 0.5f, -0.5f, -0.5f), XMFLOAT3(1.0f, 0.0f, 0.0f), 1.38f}, 
        {XMFLOAT3( 0.5f, -0.5f, 0.5f), XMFLOAT3(1.0f, 0.0f, 1.0f), 1.38f}, 
        {XMFLOAT3( 0.5f, 0.5f, -0.5f), XMFLOAT3(1.0f, 1.0f, 0.0f), 1.38f}, 
        {XMFLOAT3( 0.5f, 0.5f, 0.5f), XMFLOAT3(1.0f, 1.0f, 1.0f), 1.38f}, 
    };
</pre></p><p>&nbsp;</p><p>Now you will be able to pass parameters to the vertex shader without having to manually modify the shader itself.</p><h4>Shaders in FallFury</h4><p>There are several shaders used in FallFury, which must be selected depending on the Direct3D feature level available on the machine. A feature level determines what a video adapter can do in terms of rendering—even though Direct3D is a unified framework, it still heavily relies on how individual graphic cards can perform.</p><p>There are 5 shaders used internally for texture rendering. Specifically, there is a pixel shader, a replication vertex shader, an instancing vertex shader and geometry shaders. This could be familiar if you worked with Microsoft DirectX sprite samples before:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image016%5B3%5D.png"><img title="clip_image016" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image016_thumb.png" alt="clip_image016" width="337" height="167" border="0"></a></p><p>Given the platform limitations, geometry shaders can only be used on devices supporting Direct3D Feature Level 10. When FallFury detects that the feature level is lower than that, it has to fall back on either the instancing or the replication shaders. Some devices, such as the Microsoft Surface, are at feature level 9.1. Therefore, the replication render technique must be enforced.</p><p>Following the <a href="http://code.msdn.microsoft.com/windowsapps/Direct3D-sprite-sample-97ae6262">Microsoft DirectX Sprite Sample</a>, it is fairly easy to simply select the correct render technique once the feature level is detected with <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ff476528%28v=vs.85%29.aspx">GetFeatureLevel</a>:</p><p><pre class="brush: cpp">
auto featureLevel = m_d3dDevice-&gt;GetFeatureLevel(); 
if (featureLevel &gt;= D3D_FEATURE_LEVEL_10_0) 
{ 
    m_technique = RenderTechnique::GeometryShader; 
} 
else if (featureLevel &gt;= D3D_FEATURE_LEVEL_9_3) 
{ 
    m_technique = RenderTechnique::Instancing; 
} 
else 
{ 
    m_technique = RenderTechnique::Replication; 
    if (capacity &gt; static_cast&lt;int&gt;(Parameters::MaximumCapacityCompatible)) 
    { 
        // The index buffer format for feature-level 9.1 devices may only be 16 bits. 
        // With 4 vertices per sprite, this allows a maximum of (1 &lt;&lt; 16) / 4 sprites. 
        throw ref new Platform::InvalidArgumentException(); 
    } 
}
</pre></p><p>&nbsp;</p><p>Depending on the selected render technique, which is determined on application startup, the proper input layout is selected for each shader and is used to control the rendering pipe.</p><p>Different graphic adapters also support different <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ff471356%28v=vs.85%29.aspx">shader models</a>. You need to account for those, and before running the application, the HLSL compiler will take on the task of determining whether a proper shader component is supported by the given model. In the shader properties, make sure that you specify the used shader model, as well as the type of the shader:</p><p><a href="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image018%5B3%5D-1.jpg"><img title="clip_image018" src="http://files.channel9.msdn.com/wlwimages/1932b237046e4743a4e79e6800c0220f/clip_image018_thumb-1.jpg" alt="clip_image018" width="624" height="443" border="0"></a></p><p>Without this, you are bound to experience compile time errors that will prevent you from launching the application or deploying it to different devices.</p><h4>Conclusion</h4><p>Shaders are not an easy subject. I highly recommend reading <a href="http://http.developer.nvidia.com/CgTutorial/cg_tutorial_frontmatter.html">The Cg Tutorial</a>, published online for free by nVidia. Even though it describes the Cg shader language, it is virtually identical to HLSL and you will not have any problems using the practices you learned there in building HLSL shaders.</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Niners/rbarraza/Posts/RSS&WT.dl=0&WT.entryid=Entry:RSSView:e11fdf9075a54e749835a13f017319dd">]]></description>
      <comments>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-2-Shaders</comments>
      <itunes:summary>Introduction to ShadersFallFury not only relies on standard C&amp;#43;&amp;#43;/C# and XAML code, but also on shaders. This article is intended for developers who are not aware of what shaders are and want to know how to use them in their projects. I will talk about creating shaders, as well as the shaders used in my project. Check out the video for this article at http://channel9.msdn.com/Series/FallFury/Part-2-Shaders.&amp;nbsp; For a complete, offline version of this series, you may download a nicely formatted PDF of all the articles. Code on GPUIn simple terms, shaders are small programs that are executed on the Graphical Processing Unit (GPU) instead of the Central Processing Unit (CPU). In recent years, we’ve seen a major spike in the capabilities of graphic devices, allowing hardware manufacturers to design an execution layer tied to the GPU, therefore being able to target device-specific manipulations to a highly optimized unit. Shaders are not used for simple calculations, but rather for image processing. For example, a shader can be used to adjust image lighting or colors. Modern GPUs give access to the rendering pipeline that allows developers to execute arbitrary image processing code. This is a step forward from a fixed-function pipeline that was present in older GPUs, where image processing tasks were integrated into the hardware unit and were only able to perform a limited set of actions, such as transforms. Unlike the rendering pipeline, the fixed-function pipeline was not programmable, therefore the developers were often tied to the hardware they used for offering specific game effects, in some cases having to resort to software-based adjustments. Types of ShadersThere are different types of image manipulations that can be performed on a given input, and so there are different types of shaders designed to handle that. Currently, we can highlight three main shader types: Vertex shaders – because what the user sees on the screen is not really three-dimensional, b</itunes:summary>
      <link>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-2-Shaders</link>
      <pubDate>Wed, 23 Jan 2013 23:57:00 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-2-Shaders</guid>
      <media:thumbnail url="http://media.ch9.ms/ch9/0419/408466c0-5dee-4616-b76d-3c5e824a0419/FallFuryPart2_100.jpg" height="56" width="100"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/0419/408466c0-5dee-4616-b76d-3c5e824a0419/FallFuryPart2_220.jpg" height="124" width="220"></media:thumbnail>
      <media:thumbnail url="http://media.ch9.ms/ch9/0419/408466c0-5dee-4616-b76d-3c5e824a0419/FallFuryPart2_512.jpg" height="289" width="512"></media:thumbnail>      
      <dc:creator>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</dc:creator>
      <itunes:author>Brian Peek, Clint Rutkas, Dan Fernandez, Den Delimarsky, Rick Barraza</itunes:author>
      <slash:comments>2</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/coding4fun/articles/Fall-Fury-Part-2-Shaders/RSS</wfw:commentRss>
      <category>C#</category>
      <category>C++</category>
      <category>DirectX</category>
      <category>Windows Store App</category>
    </item>    
</channel>
</rss>