<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>brandf's XNA Indie Game blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/brandf/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/brandf/feed.xml</link>
    <description>pseudo random thoughts, ideas, etc.</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:20:53 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>How not to make a game leaderboard service.</title>
      <link>https://docs.microsoft.com/archive/blogs/brandf/how-not-to-make-a-game-leaderboard-service</link>
      <pubDate>Wed, 23 Mar 2011 21:11:14 GMT</pubDate>
      <dc:creator><![CDATA[brandf]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/brandf/2011/03/23/how-not-to-make-a-game-leaderboard-service/</guid>
      <description><![CDATA[&#160;    My recent XNA game (Taptitude) on Windows Phone 7 is doing pretty good now that we’ve...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>    <p>My recent XNA game (Taptitude) on Windows Phone 7 is doing pretty good now that we’ve released the first 4 mini-games free. In making Taptitude we decided to use WCF REST’ful web services to implement leaderboards. Being a total n00b at writing web services we incorrectly assumed everything was working perfectly and went ahead an released the game.</p>  <p>A few days later we started seeing some ridiculously high scores in the leaderboard. At first we didn’t know what the issue was and thought someone had found some clever way to cheat. This was on our ‘Draw a Circle’ mini-game, so maybe someone was tracing a circle and getting crazy scores?</p>  <p>A few days later we released “Stay Inside” and times like 23 minutes were getting submitted (a good time is more like 20 seconds). Now we knew something was up because the same user was submitting scores like that every couple minutes…not even possible.   <br />    <br />At this point, Nate realized that all of the crazy scores were from the de-DE locale. What could be so special about de-DE? We started by repro’ing the problem by setting Thread.Current.CurrentCulture to de-DE. Sure enough we started seeing the problem (among other issues). A little bit of debugging later and we narrowed in on the root cause.    <br />    <br />Q: What does the floating point number half way between 1 and 2 look like in the de-DE locale?    <br />A: 15 if you’re an idiot and parse it using the en-US locale.    <br />    <br />It it’s still not obvious what I’m talking about, consider these unfortunate facts:    <br />1) Germans (among other regions) write decimal points using a comma, where as the US uses a period.    <br />2) When parsing a float from a string using the en-US culture, comma’s are ignored.    <br />    <br />Combine these and you get something like “1020.56” in English becoming “1020,56” in German, and then our en-US web service parsing it as “102056.0”!</p>  <p>We had other issues as well with Dates, but I’ll save that for another post.   <br />    <br />Moral of the story: Test on every locale you plan to ship to, even if you’re not localizing. Oh, and make your services culture insensitive too.</p>]]></content:encoded>
    </item>
    <item>
      <title>Four Bros Studio has released Volume 1 of Taptitude on WP7 Marketplace</title>
      <link>https://docs.microsoft.com/archive/blogs/brandf/four-bros-studio-has-released-volume-1-of-taptitude-on-wp7-marketplace</link>
      <pubDate>Wed, 23 Mar 2011 20:31:56 GMT</pubDate>
      <dc:creator><![CDATA[brandf]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/brandf/2011/03/23/four-bros-studio-has-released-volume-1-of-taptitude-on-wp7-marketplace/</guid>
      <description><![CDATA[&#160;  My first XNA game for Windows Phone 7 is out the door.&#160; One thing that is nice about...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>My first XNA game for Windows Phone 7 is out the door.&#160; One thing that is nice about XNA is that I was able to leverage a ton of code from my previous Xbox 360 game (Wayne The Brain).&#160; This time around we decided to do a collection of mini-games with online leaderboards.&#160; Taptitude is the name of the collection and Taptitude: Volume 1 contains the first 5 mini games.</p>  <p>Screenshots:   <br /><a title="https://wpappshub.com/games/taptitude-volume-1" href="https://wpappshub.com/games/taptitude-volume-1">https://wpappshub.com/games/taptitude-volume-1</a>    <br />    <br />Description:    <br /></p> A collection of five competitive mini-games that are sure to test your skills. Compete to earn your spot on the weekly leaderboards, or challenge your friends in pass and play games. Trial mode includes full access to four of the five games.  <br />- Global leaderboards  <br />- Bomb Defuser  <br />- Tap Sequence  <br />- Draw a Circle  <br />- Stay Inside  <br />- Scratch   ]]></content:encoded>
    </item>
    <item>
      <title>Performance of Guide.IsTrialMode on WP7</title>
      <link>https://docs.microsoft.com/archive/blogs/brandf/performance-of-guide-istrialmode-on-wp7</link>
      <pubDate>Mon, 25 Oct 2010 19:34:34 GMT</pubDate>
      <dc:creator><![CDATA[brandf]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/brandf/2010/10/25/performance-of-guide-istrialmode-on-wp7/</guid>
      <description><![CDATA[Trial mode is an important part of every XNA game.&#160; It gives the player a taste of the...]]></description>
      <content:encoded><![CDATA[<p>Trial mode is an important part of every XNA game.&#160; It gives the player a taste of the gameplay, and wets their appetite for what they can expect after purchasing the full license.&#160; It’s therefore important to understand how to best implement trial mode in your wp7 game.</p>  <p>One common issue we’re seeing is that games assume Guide.IsTrialMode will be fast.&#160; Fast enough to call every frame.&#160; Please don’t do this!&#160; While it is fast on your unlocked developer phone, you will be surprised by how expensive this call is when your game has an actual trial license.&#160; I think Klucher did a good job of explaining the issue, so I’ll just send you his way:</p>  <p><a title="https://klucher.com/blog/trials-and-tribulations/" href="https://klucher.com/blog/trials-and-tribulations/">https://klucher.com/blog/trials-and-tribulations/</a></p>  <p>The short story is that you should not assume this call will be fast, and thus only call it at ‘load time’ in your game.&#160; Whatever that means depends on your game.</p>  <p>Happy coding!</p>]]></content:encoded>
    </item>
    <item>
      <title>On Scripting Languages in Games</title>
      <link>https://docs.microsoft.com/archive/blogs/brandf/on-scripting-languages-in-games</link>
      <pubDate>Mon, 06 Sep 2010 16:29:34 GMT</pubDate>
      <dc:creator><![CDATA[brandf]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/brandf/2010/09/06/on-scripting-languages-in-games/</guid>
      <description><![CDATA[Until recently I never really saw the point of embedding a scripting language in your game.&#160;...]]></description>
      <content:encoded><![CDATA[<p>Until recently I never really saw the point of embedding a scripting language in your game.&#160; I’m already pretty good with C#, so why would I want to use some other language to write game code?&#160; I don’t' have a staff of level designers that can sorta code either, so what’s the point?&#160; Plus it’s not a trivial amount of work to expose your game systems to scripts…I’d have a hard time justifying it as a productivity enhancement for the scale of games I work on. </p>  <p>&#160;</p>  <p>So what’s changed?</p>  <p>&#160;</p>  <p>Nothing really, I just got bored and needed an excuse to write a language.&#160; In retrospect I’m considering it for use as a game scripting system, but I’m not yet convinced it’s a good idea.</p>  <p>&#160;</p>  <p>The language I wrote is LISP-like although I played around a bit with the syntax.&#160; I chose this style of language for a few reasons:</p>  <ol>   <li>I don’t know squat about writing languages, and this seemed easy to write.&#160; It was. </li>    <li>It’s a dynamic language, which for a scripting language is a good thing IMO. </li>    <li>I’ve never used LISP before, but I’ve heard good things.&#160; What better way to learn it than to write it? </li>    <li>I like the quoting feature of LISP.&#160; It might come in handy in places where I’ve previously used XML. </li> </ol>  <p>It looks a bit like this:</p>  <pre>(if (&gt; time 90)
    (do
        (spawn-entity &quot;goomba&quot; `(100 200))
        (send-message self &quot;disable&quot;)   
    )
)</pre>

<p>As you can see, lists are formed via whitespace separated tokens surrounded in parenthesis.&#160; The first item in a list should evaluate to a function which is then called with the rest of the items as the arguments.&#160; The syntax takes a bit to get use to, but if you format it sanely it’s not too bad.&#160; And it’s a hell of a lot easier to parse/interpret than a C-like language.</p>

<p>&#160;</p>

<p>Possible uses in a game could be:</p>

<ul>
  <li>Coordinating level-specific behavior such as scripting cutscenes</li>

  <li>Scripting level-specific entity behavior.&#160; Something like “when the player presses this switch, raise that platform and enable that trigger”.</li>

  <li>In-game console used for debugging and such.</li>
</ul>

<p>All stuff that could be done without a full blown scripting language…but that’s not really the point.&#160; Sometimes it’s fun to do something just for the sake of experimentation.&#160; You never know when it’s going to turn into something you hadn’t anticipated.</p>

<p>&#160;</p>

<p>I’ve got a pretty good suite of unit tests going, but I’m still working on reducing garbage before I post it online.&#160; I’ll save that for another post.</p>]]></content:encoded>
    </item>
    <item>
      <title>Wayne the Brain redeem code give away on Reddit.com</title>
      <link>https://docs.microsoft.com/archive/blogs/brandf/wayne-the-brain-redeem-code-give-away-on-reddit-com</link>
      <pubDate>Mon, 05 Apr 2010 14:19:46 GMT</pubDate>
      <dc:creator><![CDATA[brandf]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/brandf/2010/04/05/wayne-the-brain-redeem-code-give-away-on-reddit-com/</guid>
      <description><![CDATA[I’m giving away a bunch of redeem codes on Reddit today.&#160; Leave some feedback in the comments...]]></description>
      <content:encoded><![CDATA[<p>I’m giving away a bunch of redeem codes on <a href="https://www.reddit.com/r/gaming/comments/bmpbn/reddit_my_brother_and_i_made_an_xbox_360_game/">Reddit</a> today.&#160; Leave some feedback in the comments for a redeem code.    </p>]]></content:encoded>
    </item>
    <item>
      <title>Wayne The Brain is now available on Xbox LIVE Marketplace</title>
      <link>https://docs.microsoft.com/archive/blogs/brandf/wayne-the-brain-is-now-available-on-xbox-live-marketplace</link>
      <pubDate>Fri, 02 Apr 2010 16:28:10 GMT</pubDate>
      <dc:creator><![CDATA[brandf]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/brandf/2010/04/02/wayne-the-brain-is-now-available-on-xbox-live-marketplace/</guid>
      <description><![CDATA[Wayne the Brain has passed peer review and is now available on Xbox LIVE Marketplace for 80pts ($1...]]></description>
      <content:encoded><![CDATA[<p>Wayne the Brain has passed peer review and is now available on Xbox LIVE Marketplace for 80pts ($1 US).</p>  <p>&#160;</p>  <p>If you like fun physics games, then give it a try.&#160; You can download it from the Marketplace-&gt;Indie Games section of the Xbox Dashboard, or queue up the download from xbox.com (link below).</p>  <p>&#160;</p>  <p>Let me know what you think of the game in the comments.</p>  <p>&#160;</p>  <p>Trailer:   <br /><a href="https://www.youtube.com/watch?v=uGSCrymtZOQ">https://www.youtube.com/watch?v=uGSCrymtZOQ</a></p>  <p>Download:   <br /><a href="https://tinyurl.com/yl3wvkr">https://tinyurl.com/yl3wvkr</a></p>  <p>Screenshots:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/WayneTheBrainisnowavailableonXboxLIVEMar_E796/CatalogImage%5B1%5D.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/WayneTheBrainisnowavailableonXboxLIVEMar_E796/CatalogImage%5B1%5D.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="CatalogImage[1]" border="0" alt="CatalogImage[1]" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/WayneTheBrainisnowavailableonXboxLIVEMar_E796/CatalogImage%5B1%5D_thumb.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/WayneTheBrainisnowavailableonXboxLIVEMar_E796/CatalogImage%5B1%5D_thumb.png" width="244" height="139" /></a> </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/WayneTheBrainisnowavailableonXboxLIVEMar_E796/CatalogImage%5B1%5D_1.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/WayneTheBrainisnowavailableonXboxLIVEMar_E796/CatalogImage%5B1%5D_1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="CatalogImage[1]" border="0" alt="CatalogImage[1]" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/WayneTheBrainisnowavailableonXboxLIVEMar_E796/CatalogImage%5B1%5D_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/WayneTheBrainisnowavailableonXboxLIVEMar_E796/CatalogImage%5B1%5D_thumb_1.png" width="244" height="139" /></a> </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/WayneTheBrainisnowavailableonXboxLIVEMar_E796/CatalogImage%5B1%5D_2.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/WayneTheBrainisnowavailableonXboxLIVEMar_E796/CatalogImage%5B1%5D_2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="CatalogImage[1]" border="0" alt="CatalogImage[1]" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/WayneTheBrainisnowavailableonXboxLIVEMar_E796/CatalogImage%5B1%5D_thumb_2.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/WayneTheBrainisnowavailableonXboxLIVEMar_E796/CatalogImage%5B1%5D_thumb_2.png" width="244" height="139" /></a> </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/WayneTheBrainisnowavailableonXboxLIVEMar_E796/CatalogImage%5B1%5D_3.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/WayneTheBrainisnowavailableonXboxLIVEMar_E796/CatalogImage%5B1%5D_3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="CatalogImage[1]" border="0" alt="CatalogImage[1]" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/WayneTheBrainisnowavailableonXboxLIVEMar_E796/CatalogImage%5B1%5D_thumb_3.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/WayneTheBrainisnowavailableonXboxLIVEMar_E796/CatalogImage%5B1%5D_thumb_3.png" width="244" height="139" /></a></p>]]></content:encoded>
    </item>
    <item>
      <title>XNA Developer Talk Series Event Today</title>
      <link>https://docs.microsoft.com/archive/blogs/brandf/xna-developer-talk-series-event-today</link>
      <pubDate>Wed, 24 Mar 2010 10:13:07 GMT</pubDate>
      <dc:creator><![CDATA[brandf]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/brandf/2010/03/24/xna-developer-talk-series-event-today/</guid>
      <description><![CDATA[Today (at 4pm PST) I’m giving a talk via Live Meeting about how you can use UI animations in your...]]></description>
      <content:encoded><![CDATA[<p>Today (at 4pm PST) I’m giving a talk via Live Meeting about how you can use UI animations in your game to give it the extra polish that’s needed to stand out in a crowded marketplace.</p>  <p>&#160;</p>  <p>For more information about how to tune in to this talk please visit the creators club site:</p>  <p><a title="https://creators.xna.com/en-US/developerseries" href="https://creators.xna.com/en-US/developerseries">https://creators.xna.com/en-US/developerseries</a></p>  <p>&#160;</p>  <p>My talk is focused on main menu animations, so it may be hard to pick up on the Live Meeting video stream.&#160; If you are following along with the talk and would like to see the demo in action, please check out the video and/or demo code below:</p>  <p><iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="https://cid-b687a23c9e1d24fd.skydrive.live.com/embedicon.aspx/Public/DevTalkAnimation.wmv" frameborder="0" marginwidth="0" scrolling="no"></iframe>&#160; <iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="https://cid-b687a23c9e1d24fd.skydrive.live.com/embedicon.aspx/Public/DevTalkAnimation.zip" frameborder="0" marginwidth="0" scrolling="no"></iframe></p>  <p>&#160;</p>  <p>If you can’t make it to today’s talk, I’ll be repeating the talk on Friday (3/26/2010) at 4pm PST.&#160; After this talk I’ll post the slides online.</p>]]></content:encoded>
    </item>
    <item>
      <title>Wayne The Brain in Peer Review</title>
      <link>https://docs.microsoft.com/archive/blogs/brandf/wayne-the-brain-in-peer-review</link>
      <pubDate>Mon, 15 Mar 2010 12:50:00 GMT</pubDate>
      <dc:creator><![CDATA[brandf]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/brandf/2010/03/15/wayne-the-brain-in-peer-review/</guid>
      <description><![CDATA[My brother Nathan and I have been working on an XNA Game Studio game called “Wayne The Brain” for...]]></description>
      <content:encoded><![CDATA[<P>My brother Nathan and I have been working on an XNA Game Studio game called “Wayne The Brain” for the past few months.&nbsp; Recently we completed the game and submitted it to peer review.&nbsp; </P>
<P>If you’re a creators club member, we would really appreciate a review: <A title=https://catalog.xna.com/en-US/GameDetails.aspx?catalogEntryId=86175871-8cf3-45c6-93cb-f21daee8a008&amp;type=1 href="https://catalog.xna.com/en-US/GameDetails.aspx?catalogEntryId=86175871-8cf3-45c6-93cb-f21daee8a008&amp;type=1" mce_href="https://catalog.xna.com/en-US/GameDetails.aspx?catalogEntryId=86175871-8cf3-45c6-93cb-f21daee8a008&amp;type=1">https://catalog.xna.com/en-US/GameDetails.aspx?catalogEntryId=86175871-8cf3-45c6-93cb-f21daee8a008&amp;type=1</A></P>
<P>Here’s the official trailer:</P>
<OBJECT width=480 height=385><PARAM NAME="movie" VALUE="https://www.youtube.com/v/uGSCrymtZOQ&amp;hl=en_US&amp;fs=1&amp;"><PARAM NAME="allowFullScreen" VALUE="true"><PARAM NAME="allowscriptaccess" VALUE="always">
<embed src="https://www.youtube.com/v/uGSCrymtZOQ&amp;hl=en_US&amp;fs=1&amp;" mce_src="https://www.youtube.com/v/uGSCrymtZOQ&amp;hl=en_US&amp;fs=1&amp;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></OBJECT>]]></content:encoded>
    </item>
    <item>
      <title>Using retained sprites (ZoomEngine.Graphics) and ZoomEngine.Animation Part 3</title>
      <link>https://docs.microsoft.com/archive/blogs/brandf/using-retained-sprites-zoomengine-graphics-and-zoomengine-animation-part-3</link>
      <pubDate>Thu, 18 Feb 2010 14:11:52 GMT</pubDate>
      <dc:creator><![CDATA[brandf]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/brandf/2010/02/18/using-retained-sprites-zoomengine-graphics-and-zoomengine-animation-part-3/</guid>
      <description><![CDATA[When you look at most of the sample code that’s out there for doing 2D XNA games you may notice that...]]></description>
      <content:encoded><![CDATA[<p>When you look at most of the sample code that’s out there for doing 2D XNA games you may notice that there is a tendency to sprinkle in the drawing code all over the place.&#160; Simple samples/tutorials will put it directly in Game.Draw(…) while more complicated projects usually have it inside the game ‘entities’.</p>  <p>In this post, I’d like to present an alternative method that has a number of advantages.&#160; I call this ‘The Retained Sprite Method’.&#160; This isn’t a new concept, and there is nothing magical or complicated about what I’m going to show you, but it will go along way to help clean up your code and make more reusable ‘engine’ components.</p>  <h3>What is the retained sprite method?</h3>  <p>The idea is that you put all of your drawing code in exactly one place.&#160; I’ll call this the DrawingContext.&#160; Furthermore, your game entities do not typically use the DrawingContext to draw anything…only Sprites do.&#160; A Sprites is a ‘dumb’ (no Update) object that describes what/where to draw.&#160; Your game entities (player, enemy, boss, etc) do all the ‘thinking’ (Update) and create/retain sprites in a sprite tree.&#160; Each frame the entities do not have to do anything to draw the sprites, just being in the tree means the entity is drawn.</p>  <p>&#160;</p>  <p>Lets look a class diagram:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/UsingretainedspritesZoomE.AnimationPart3_C7A3/image_2.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/UsingretainedspritesZoomE.AnimationPart3_C7A3/image_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/UsingretainedspritesZoomE.AnimationPart3_C7A3/image_thumb.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/UsingretainedspritesZoomE.AnimationPart3_C7A3/image_thumb.png" width="641" height="589" /></a> </p>  <p>&#160;</p>  <p>What you see above is a very simple retained sprite system.&#160; This system supports two types of Sprites.&#160; </p>  <p><strong>FrameSprite</strong> will draw a single image to the screen (a Frame describes the Texture, SourceRect, and SpriteEffect to use).</p>  <p><strong>TextSprite</strong> will draw a string of text to the screen using a given font &amp; alignment.</p>  <p>You can imagine how such a system could be extended.&#160; In my game engine I have other types of sprites like AvatarSprite, AnimatedSprite, MovieSprite, etc.   <br />    <br />You can then build higher level components on top of this.&#160; For example, layout/controls framework uses the sprite tree for it’s rendering.</p>  <h3>Some of the advantages of doing your drawing this way are:</h3>  <ol>   <li>You don’t have spriteBatch.Draw code sprinkled all over your codebase.&#160; It’s all in DrawingContext, so you can upgrade/port to new rendering systems easily. </li>    <li>Your game code is more declarative (read ‘clean’), because you’re describing what to draw, instead of how to draw it. </li>    <li>Because it’s more declarative, it naturally lends itself to using an animation system as described in <a href="https://blogs.msdn.com/brandf/archive/2009/10/28/zoomengine-animation-part-1.aspx">previous</a> <a href="https://blogs.msdn.com/brandf/archive/2009/11/04/zoomengine-animation-part-2.aspx">posts</a>. </li>    <li>Things like layers, multiple cameras, culling, etc become much easier when you retain a sprite tree. </li>    <li>Sprites can have Children, so doing relative motion is trival.&#160; Whenever a parent sprite moves/rotates, all children are also moved/rotated.&#160; The same applies to Scale/Color.</li> </ol>  <p>The sample code below shows how to use this sprite system, and as a bonus I added plenty of animations to show how powerful the combinations of a retained sprite tree with an animation system can be.    <br />    <br />If you’re not convinced that this is the way to go, then I invite you to re-create this sample without using the retained sprite tree &amp; post it in the comments.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/UsingretainedspritesZoomE.AnimationPart3_C7A3/retainedsprite_2.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/UsingretainedspritesZoomE.AnimationPart3_C7A3/retainedsprite_2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="retainedsprite" border="0" alt="retainedsprite" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/UsingretainedspritesZoomE.AnimationPart3_C7A3/retainedsprite_thumb.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/UsingretainedspritesZoomE.AnimationPart3_C7A3/retainedsprite_thumb.png" width="244" height="192" /></a> </p> <iframe style="padding-bottom: 0px; background-color: #fcfcfc; padding-left: 0px; width: 98px; padding-right: 0px; height: 115px; padding-top: 0px" title="Preview" marginheight="0" src="https://cid-b687a23c9e1d24fd.skydrive.live.com/embedicon.aspx/Public/Blog/ZoomEngine.Graphics.Example1.zip" frameborder="0" marginwidth="0" scrolling="no"></iframe>]]></content:encoded>
    </item>
    <item>
      <title>Adding 2D physics to your XNA Game Studio game. Part 1</title>
      <link>https://docs.microsoft.com/archive/blogs/brandf/adding-2d-physics-to-your-xna-game-studio-game-part-1</link>
      <pubDate>Mon, 04 Jan 2010 13:02:00 GMT</pubDate>
      <dc:creator><![CDATA[brandf]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/brandf/2010/01/04/adding-2d-physics-to-your-xna-game-studio-game-part-1/</guid>
      <description><![CDATA[One of my hobby projects (again, not Microsoft official) is a port of the Box2D physics...]]></description>
      <content:encoded><![CDATA[<p>One of my hobby projects (again, not Microsoft official) is a port of the <a href="https://code.google.com/p/box2d/" mce_href="https://code.google.com/p/box2d/">Box2D</a> physics engine.&#160; My brother <a href="https://twitter.com/GuyNamedNate" mce_href="https://twitter.com/GuyNamedNate">Nathan Furtwangler</a> and I have been porting Box2D to C#/XNA and we recently posted it on CodePlex under the MIT license.&#160; We call it <a href="https://box2dxna.codeplex.com/" mce_href="https://box2dxna.codeplex.com/">Box2D.XNA</a>.&#160; It’s our goal to keep it in sync with the latest <a href="https://code.google.com/p/box2d/" mce_href="https://code.google.com/p/box2d/">Box2D</a> changes and to optimize it for the Xbox 360.&#160; In this post, I’ll give you a basic overview of Box2D.XNA and show how to use it in your game.</p>  <p>Lets start with the basic hierarchy of the objects you’ll be working with:    <br /><strong>World</strong> – the root object for the physics simulation. Step this once a frame &amp; you’re simulating physics!&#160; <br />&#160; <strong>Body</strong> – Multiple bodies can be added to the world.&#160; These are the objects that interact with each other via collisions.     <br />&#160;&#160;&#160; <strong>Fixture</strong> – A body is made up of multiple fixtures.&#160; Fixtures combine a shape with material properties to form the overall “look and feel” of the body.&#160; An example of a fixtures is a bouncy, slippery circle that’s highly massive.     <br />&#160;&#160;&#160;&#160;&#160; <strong>Shape</strong> – Each fixture has a single shape object that defines its mathematical bounds.&#160; Box2D supports circles and convex polygons.&#160; Multiple fixtures can be added to a body to make more complicated shapes.&#160; <br />&#160; <strong>Joint</strong> – The world has a set of joints that bind Bodies together.&#160; Different joints do this using various constraints.&#160; For example a Distance joint will limit the distance that two points on two bodies can separate.&#160; Box2D.XNA has lots of joint types that we can talk more about in another post.     <br />&#160; <strong>Contact</strong> – While stepping the world, Bodies will collide &amp; respond to collisions realistically.&#160; This is accomplished using Contacts.&#160; You can listen in to the contact being generated and use this information in your game.&#160; Want to know when the players sword strikes the skull of the final boss?&#160; Listen for a contact between the two, and you’re good to go.</p>  <p>   <br />Now that we’re familiar with the basic objects of a physics simulation, lets get our hands dirty and make something cool!&#160; </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_4.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_4.png" mce_href="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_thumb_1.png" width="244" height="192" mce_src="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_thumb_1.png" /></a> <a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_6.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_6.png" mce_href="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_6.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_thumb_2.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_thumb_2.png" width="244" height="192" mce_src="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_thumb_2.png" /></a> <a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_8.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_8.png" mce_href="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_8.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_thumb_3.png" original-url="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_thumb_3.png" width="244" height="192" mce_src="https://blogs.msdn.com/blogfiles/brandf/WindowsLiveWriter/Adding2DphysicstoyourXNAGameStudio.Part1_10867/image_thumb_3.png" /></a> </p> <iframe title="Preview" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" style="width:98px;height:115px;padding:0;background-color:#fcfcfc;" src="https://cid-b687a23c9e1d24fd.skydrive.live.com/embedicon.aspx/Public/Blog/PhysicsDemo.Part1.zip"></iframe>  <p>To get started you’ll need to download/install <a href="https://www.microsoft.com/downloads/details.aspx?FamilyID=80782277-d584-42d2-8024-893fcd9d3e82&amp;displaylang=en" mce_href="https://www.microsoft.com/downloads/details.aspx?FamilyID=80782277-d584-42d2-8024-893fcd9d3e82&amp;displaylang=en">XNA Game Studio 3.1</a> if you don’t already have it.&#160; Next extract the zip above and open the project in Visual Studio.&#160; </p>  <p>I’ve included the latest Box2D.XNA source (as of this writing, changeset <a href="https://box2dxna.codeplex.com/SourceControl/changeset/view/34963" mce_href="https://box2dxna.codeplex.com/SourceControl/changeset/view/34963">34963</a>), but if you’re planning on making your own physics project you’ll want to check for a <a href="https://box2dxna.codeplex.com/SourceControl/list/changesets" mce_href="https://box2dxna.codeplex.com/SourceControl/list/changesets">newer</a> version.</p>  <p>The goal for this project is to take an image and approximate it with little circles.&#160; Then when a key is pressed we’ll start simulating the physics and the balls will drop/bounce all over the place.&#160; Sounds like fun, lets get started…</p>  <p>The first thing we need to do is to create the physics World.&#160; The first parameter is the gravity, and the second argument tells the simulation to make objects go to sleep if they aren’t interacting with anything.</p>  <div style="font-family: courier new; background: white; color: black; font-size: 10pt">   <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; _physicsWorld = <span style="color: blue">new</span> <span style="color: #2b91af">World</span>(<span style="color: blue">new</span> <span style="color: #2b91af">Vector2</span>(0, 100), <span style="color: blue">true</span>);</p> </div>  <p>I used a gravity of 100 because I’m dealing with pixels/s^2.&#160; Normally you’d want to work in meters &amp; seconds or else things get a bit unstable.</p>  <p>Next we need to add bodies to it.&#160; In this case I will randomly position some circles…you can look at the code to see how I decide on a location, but here’s the code to add the Body.</p>  <div style="font-family: courier new; background: white; color: black; font-size: 10pt">   <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">private</span> <span style="color: blue">void</span> AddCircle(<span style="color: #2b91af">Vector2</span> position, <span style="color: #2b91af">Color</span> color)</p>    <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>    <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">var</span> circle = <span style="color: blue">new</span> <span style="color: #2b91af">CircleShape</span>();</p>    <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; circle._radius = _circleRadius;</p>    <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">var</span> fd = <span style="color: blue">new</span> <span style="color: #2b91af">FixtureDef</span>();</p>    <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; fd.shape = circle;</p>    <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; fd.restitution = 0.98f;</p>    <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; fd.friction = 0.1f;</p>    <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; fd.density = 1.0f;</p>    <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">BodyDef</span> bd = <span style="color: blue">new</span> <span style="color: #2b91af">BodyDef</span>();</p>    <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bd.type = <span style="color: #2b91af">BodyType</span>.Dynamic;</p>    <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bd.position =&#160; position;</p>    <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">var</span> body = _physicsWorld.CreateBody(bd);</p>    <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; body.CreateFixture(fd);</p>    <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; body.SetUserData(color);</p>    <p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p> </div>  <p>Now we just need to step the simulation every update (after you press a key):</p>  <blockquote>   <div style="font-family: courier new; background: white; color: black; font-size: 10pt">     <p style="margin: 0px">_physicsWorld.Step((<span style="color: blue">float</span>)gameTime.ElapsedGameTime.TotalSeconds, 10, 3);</p>   </div> </blockquote>  <p mce_keep="true">&#160;</p>  <p mce_keep="true">&#160;</p>  <p mce_keep="true">&#160;</p>  <p>The arguments to this method control the time step, and how accurate the simulation is.&#160; Feel free to experiment with the last two for your scene.</p>  <p>That’s it!&#160; We just made a really cool app in only 10 minutes of coding!&#160; Feel free to use Box2D.XNA in your XNA projects, and if you make anything cool leave a comment with a link.</p>]]></content:encoded>
    </item>
  </channel>
</rss>