<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>XNA Diaries : XNA</title><link>http://blogs.msdn.com/garykac/archive/tags/XNA/default.aspx</link><description>Tags: XNA</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>XNAExtras update</title><link>http://blogs.msdn.com/garykac/archive/2006/12/01/xnaextras-update.aspx</link><pubDate>Fri, 01 Dec 2006 18:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1184551</guid><dc:creator>garykac</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/garykac/comments/1184551.aspx</comments><wfw:commentRss>http://blogs.msdn.com/garykac/commentrss.aspx?PostID=1184551</wfw:commentRss><description>&lt;P&gt;This is a minor update:&lt;/P&gt;
&lt;P&gt;Beta2 update (ContentManager)&lt;BR&gt;Minor bug fix with TextBoxes not deleting their backgrounds.&lt;BR&gt;Initial stab at compiling for the 360 (by #ifdef'ing&amp;nbsp;references to Texture2D.FromFile so that they can be removed easily)&lt;BR&gt;Temporarily remove CollisionDemo since it's acting up under beta2 (there are reports that it was acting up under beta1, but I was unable to repro them...) This demo will&amp;nbsp;come back once these bugs are fixed.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1184551" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/garykac/attachment/1184551.ashx" length="525175" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/garykac/archive/tags/XNA/default.aspx">XNA</category></item><item><title>BMFontGen update (1119)</title><link>http://blogs.msdn.com/garykac/archive/2006/11/19/bmfontgen-update-_2800_1119_2900_.aspx</link><pubDate>Sun, 19 Nov 2006 22:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1101166</guid><dc:creator>garykac</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/garykac/comments/1101166.aspx</comments><wfw:commentRss>http://blogs.msdn.com/garykac/commentrss.aspx?PostID=1101166</wfw:commentRss><description>&lt;P&gt;I had a request to&amp;nbsp;add an option to expand each glyph with padding pixels, and I'm finally getting around to doing it.&lt;/P&gt;
&lt;P&gt;To add&amp;nbsp;&lt;EM&gt;n&lt;/EM&gt; pixels of padding around each glyph, you can now&amp;nbsp;use the&amp;nbsp;glyph pad option: &lt;STRONG&gt;-gpad &lt;EM&gt;n&lt;/EM&gt;&lt;/STRONG&gt;. If you only want padding in the x or y direction, then you can use &lt;STRONG&gt;-gpadx&lt;/STRONG&gt; or &lt;STRONG&gt;-gpady&lt;/STRONG&gt;. Adding padding will not affect how the font is displayed, except that additional transparent "padding" pixels will be copied.&lt;/P&gt;
&lt;P&gt;In general, you&amp;nbsp;don't need to use these options, but they can&amp;nbsp;be useful if you intend to&amp;nbsp;manipulate the font bitmap&amp;nbsp;in such a way that the glyphs expand in size. If you do not intend to edit the font bitmap, then you don't need to use these options.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1101166" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/garykac/attachment/1101166.ashx" length="23209" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/garykac/archive/tags/XNA/default.aspx">XNA</category></item><item><title>BitmapFont update for beta2 (Finally!)</title><link>http://blogs.msdn.com/garykac/archive/2006/11/18/bitmapfont-update-for-beta2-finally.aspx</link><pubDate>Sun, 19 Nov 2006 02:33:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1101130</guid><dc:creator>garykac</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/garykac/comments/1101130.aspx</comments><wfw:commentRss>http://blogs.msdn.com/garykac/commentrss.aspx?PostID=1101130</wfw:commentRss><description>&lt;P&gt;As you've probably surmised from the last post, I seem to be somewhat loose in my interpretation of "later this week".&lt;/P&gt;
&lt;P&gt;Attached is an updated version (finally!) of the BitmapFont.cs class along with its corresponding demonstration project.&lt;/P&gt;
&lt;P&gt;Note that this update only covers the BitmapFont class, not the entire XNA Extras package. I hope to have an updated version of all the&amp;nbsp;XNA Extras classes&amp;nbsp;sometime "later this week"...&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1101130" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/garykac/attachment/1101130.ashx" length="82100" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/garykac/archive/tags/XNA/default.aspx">XNA</category></item><item><title>XNA Extras and Beta2</title><link>http://blogs.msdn.com/garykac/archive/2006/11/02/xna-extras-and-beta2.aspx</link><pubDate>Thu, 02 Nov 2006 21:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:934612</guid><dc:creator>garykac</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/garykac/comments/934612.aspx</comments><wfw:commentRss>http://blogs.msdn.com/garykac/commentrss.aspx?PostID=934612</wfw:commentRss><description>&lt;P&gt;This is a heads-up that the current release of XNA Extras requires some changes before it will work with the newly released &lt;A class="" href="http://blogs.msdn.com/xna/archive/2006/11/01/xna-game-studio-express-beta-2-available-for-download.aspx" mce_href="http://blogs.msdn.com/xna/archive/2006/11/01/xna-game-studio-express-beta-2-available-for-download.aspx"&gt;XNA Game Studio Express Beta 2&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;I'm hoping to find some time later this week (yes, I know it's already late in the week) and get an updated version up this weekend. Sorry about the delay!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=934612" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/garykac/archive/tags/XNA/default.aspx">XNA</category><category domain="http://blogs.msdn.com/garykac/archive/tags/Games/default.aspx">Games</category></item><item><title>Colliding sprites in XNAExtras</title><link>http://blogs.msdn.com/garykac/archive/2006/09/24/769335.aspx</link><pubDate>Sun, 24 Sep 2006 18:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:769335</guid><dc:creator>garykac</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/garykac/comments/769335.aspx</comments><wfw:commentRss>http://blogs.msdn.com/garykac/commentrss.aspx?PostID=769335</wfw:commentRss><description>&lt;P&gt;The latest release of XNAExtras added support for sprite collisions, and allows the collision detection to be either bounding box&amp;nbsp;(bbox) or&amp;nbsp;pixel based. This is settable per sprite - some sprites can&amp;nbsp;use bboxes and others can use pixels. The sprites will collide appropriately with each other even if they can't agree on how to do it.&lt;/P&gt;
&lt;P&gt;Here's a simple tutorial for how to use the collision detection built into XNAExtras:&lt;/P&gt;
&lt;P&gt;(1) Create an XSpriteManager.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;m_mgrSprites = &lt;FONT color=#000080&gt;new&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;XSpriteManager&lt;/FONT&gt;();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;(2) Create an XSprite.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;m_mgrSprites.AddTexture(&lt;FONT color=#ff0000&gt;"tex"&lt;/FONT&gt;, &lt;FONT color=#ff0000&gt;"texture.png"&lt;/FONT&gt;, 64, 64);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&lt;FONT color=#0000ff&gt;XSprite&lt;/FONT&gt; s1 = m_mgrSprites.AddSprite(&lt;FONT color=#ff0000&gt;"ball1"&lt;/FONT&gt;, &lt;FONT color=#ff0000&gt;"tex"&lt;/FONT&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;(3) Create another XSprite so that you have something to collide with.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&lt;FONT color=#0000ff&gt;XSprite&lt;/FONT&gt; s2 = m_mgrSprites.AddSprite(&lt;FONT color=#ff0000&gt;"ball2"&lt;/FONT&gt;, &lt;FONT color=#ff0000&gt;"tex"&lt;/FONT&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;(4) Enable collisions for these two sprites. For bounding box collisions, use:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;s1.SetCollideable(&lt;FONT color=#000080&gt;true&lt;/FONT&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;s2.SetCollideable(&lt;FONT color=#000080&gt;true&lt;/FONT&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;If you want pixel based collisions, use:&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;s1.SetCollideable(&lt;FONT color=#000080&gt;true&lt;/FONT&gt;, &lt;FONT color=#0000ff&gt;XSpriteManager&lt;/FONT&gt;.&lt;FONT color=#0000ff&gt;CollisionFlags&lt;/FONT&gt;.Pixel, 0x40);&lt;BR&gt;&amp;nbsp;&amp;nbsp;s2.SetCollideable(&lt;FONT color=#000080&gt;true&lt;/FONT&gt;, &lt;FONT color=#0000ff&gt;XSpriteManager&lt;/FONT&gt;.&lt;FONT color=#0000ff&gt;CollisionFlags&lt;/FONT&gt;.Pixel, 0x40);&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;where 0x40 is the alpha value of the sprite that defines the collideable part of the sprite - any alpha value &amp;gt;= this value will be added to the sprite's collision mask.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;(5) In your Update method, after you've moved&amp;nbsp;your sprites around a bit, you can check for collisions using CheckSpriteCollisions:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&lt;FONT color=#0000ff&gt;List&lt;/FONT&gt;&amp;lt;&lt;FONT color=#0000ff&gt;XSpriteManager&lt;/FONT&gt;.&lt;FONT color=#0000ff&gt;SpriteCollision&lt;/FONT&gt;&amp;gt; aColl = m_mgrSprites.CheckSpriteCollisions();&lt;/FONT&gt;&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;This method returns a list of collisions that were detected. It returns null if there are no collisions.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;(6) To handle collisions, simply walk the list of collisions and do whatever you feel is appropriate.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&lt;FONT color=#000080&gt;if&lt;/FONT&gt; (aColl != &lt;FONT color=#000080&gt;null&lt;/FONT&gt;)&lt;BR&gt;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// handle the collisions&lt;BR&gt;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=#000080&gt;foreach&lt;/FONT&gt; (&lt;FONT color=#0000ff&gt;XSpriteManager&lt;/FONT&gt;.&lt;FONT color=#0000ff&gt;SpriteCollision&lt;/FONT&gt; c &lt;FONT color=#000080&gt;in&lt;/FONT&gt; aColl)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;BR&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;// if colliding with another sprite...&lt;BR&gt;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;FONT color=#000080&gt;if&lt;/FONT&gt; (c.Type == &lt;FONT color=#0000ff&gt;XSpriteManager&lt;/FONT&gt;.&lt;FONT color=#0000ff&gt;CollisionType&lt;/FONT&gt;.Sprite)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;BR&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // handle&amp;nbsp;collision between c.Sprite and c.Sprite2&lt;BR&gt;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp; }&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;A working demo of collision detection is given in the CollisionDemo project included with the &lt;A href="http://blogs.msdn.com/garykac/articles/749188.aspx"&gt;XNAExtras download&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=769335" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/garykac/archive/tags/XNA/default.aspx">XNA</category></item><item><title>XNAExtras build 0923 release</title><link>http://blogs.msdn.com/garykac/archive/2006/09/23/768903.aspx</link><pubDate>Sun, 24 Sep 2006 09:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:768903</guid><dc:creator>garykac</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/garykac/comments/768903.aspx</comments><wfw:commentRss>http://blogs.msdn.com/garykac/commentrss.aspx?PostID=768903</wfw:commentRss><description>&lt;P&gt;Major addition for this version: collision detection has been added to XSpriteManager. Both bounding box and pixel based (mix-n-match sprites of different types). Also boundary collisions. These are demoed in the bouncy CollisionDemo example:&lt;/P&gt;
&lt;P align=center&gt;&lt;A href="http://blogs.msdn.com/photos/garykac/images/768840/original.aspx"&gt;&lt;IMG src="http://blogs.msdn.com/photos/garykac/images/768840/473x375.aspx"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;From the release notes:&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;(BMFontGen) Fixed bug where including undefined chars in your font -range would cause a crash&lt;BR&gt;(BitmapFont) Changed loading embedded resources - now the resource name is specified in the same format as file-based resources&lt;BR&gt;(BitmapFont) Fixed bug where font files wouldn't be found unless they were in a subdirectory&lt;BR&gt;(TextBox) Added accessors for the text string&lt;BR&gt;(XSpriteManager) Changed default FPS to 60&lt;BR&gt;(XSpriteManager) Added support for collisions&lt;BR&gt;(TexturePool) *Really* fixed bug in AddTexture(string,Color) where the texture wasn't being created if the GraphicsDevice already existed - the fix got lost for the last release&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P dir=ltr&gt;&lt;EM&gt;Thanks to redwyre, David Zakar (DMZ), Martin Szinger&amp;nbsp;and Matt Moore for comments/suggestions.&lt;/EM&gt;&lt;/P&gt;
&lt;P dir=ltr&gt;You can download the&amp;nbsp;0923 build of XNAExtras&amp;nbsp;&lt;A href="http://blogs.msdn.com/garykac/articles/749188.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=768903" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/garykac/archive/tags/XNA/default.aspx">XNA</category></item><item><title>Separating your code and data</title><link>http://blogs.msdn.com/garykac/archive/2006/09/17/759249.aspx</link><pubDate>Sun, 17 Sep 2006 20:15:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:759249</guid><dc:creator>garykac</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/garykac/comments/759249.aspx</comments><wfw:commentRss>http://blogs.msdn.com/garykac/commentrss.aspx?PostID=759249</wfw:commentRss><description>&lt;P&gt;In the &lt;A href="http://blogs.msdn.com/garykac/archive/2006/09/16/758576.aspx"&gt;previous post&lt;/A&gt;, I talked about creating border art and using it in your game. One problem with the approach shown is that&amp;nbsp;the description of the texture contents - the sprite locations and boundaries - is stored in the game code. This means that if you want to&amp;nbsp;update the border artwork for a future version of your game, you need to make parallel code modifications&amp;nbsp;and then recompile.&lt;/P&gt;
&lt;P&gt;A&amp;nbsp;nicer way of doing this is to keep the description of the texture contents in a file alongside the texture. This would allow you to change the appearance of your game without needing to recompile - useful if you're programming by yourself, and crucial if you're developing the game where someone else is helping out with the artwork.&lt;/P&gt;
&lt;P&gt;This approach is supported in the XNAExtras class library by allowing texture and sprite information to be loaded from an XML file. A simple descriptor file is:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;lt;?xml &lt;FONT color=#ff0000&gt;version&lt;/FONT&gt;=&lt;FONT color=#0000ff&gt;"1.0"&lt;/FONT&gt; &lt;FONT color=#ff0000&gt;encoding&lt;/FONT&gt;=&lt;FONT color=#0000ff&gt;"UTF-8"&lt;/FONT&gt; ?&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;lt;texinfo&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;lt;textures&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;texture &lt;FONT color=#ff0000&gt;name&lt;/FONT&gt;=&lt;FONT color=#0000ff&gt;"whiteball"&lt;/FONT&gt; &lt;FONT color=#ff0000&gt;src&lt;/FONT&gt;=&lt;FONT color=#0000ff&gt;"white ball.png"&lt;/FONT&gt; &lt;FONT color=#ff0000&gt;size&lt;/FONT&gt;=&lt;FONT color=#0000ff&gt;"64x64"&lt;/FONT&gt; /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/textures&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;lt;sprites&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;sprite &lt;FONT color=#ff0000&gt;name&lt;/FONT&gt;=&lt;FONT color=#0000ff&gt;"red"&lt;/FONT&gt; &lt;FONT color=#ff0000&gt;tex&lt;/FONT&gt;=&lt;FONT color=#0000ff&gt;"whiteball"&lt;/FONT&gt; &lt;FONT color=#ff0000&gt;pos&lt;/FONT&gt;=&lt;FONT color=#0000ff&gt;"50,50"&lt;/FONT&gt; &lt;FONT color=#ff0000&gt;tint&lt;/FONT&gt;=&lt;FONT color=#0000ff&gt;"#ff0000"&lt;/FONT&gt; /&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/sprites&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;lt;/texinfo&amp;gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;This XML file creates a single sprite based on the "white ball.png" texture, adds a red tint and positions the sprite at (50,50). While perhaps a bit of overkill for this simple texture, once you start having multiple sprites in the same texture (as you should), these descriptor files can be quite useful.&lt;/P&gt;
&lt;P&gt;To load a texture definition file into your game, simply use:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;sprites.LoadSprites(&lt;FONT color=#ff0000&gt;"spriteinfo.xml"&lt;/FONT&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Where &lt;FONT face="Courier New" size=2&gt;sprites&lt;/FONT&gt; is your game's XSpriteManager. If you want to interact with this sprite in your code (for example, to move it around the screen), you can ask the XSpriteManager to return a reference to it using:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp; &lt;FONT color=#0000ff&gt;XSprite&lt;/FONT&gt; s = sprites.GetSprite(&lt;FONT color=#ff0000&gt;"red"&lt;/FONT&gt;) &lt;FONT color=#000080&gt;as&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;XSprite&lt;/FONT&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;You can find working examples of LoadSprites in the TextBoxDemo and XSpritesDemo projects (included with the XNAExtras download).&lt;/P&gt;
&lt;P align=center&gt;&lt;IMG src="http://blogs.msdn.com/photos/garykac/images/759301/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;To assist with creating these "texture information" files, I've created an XML Schema Definition (XSD) file that you can use to perform basic validation. This XSD file (TextureInfo.xsd) is included as part of XNAExtras and is located in the "XML Schema" directory. To use it, copy the XSD file into the same directory as your XML file and replace your&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;lt;texinfo&amp;gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;tag at the beginning of the file with the following mess:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;lt;texinfo&lt;BR&gt;&amp;nbsp;&amp;nbsp;xmlns="http://xna.microsoft.com/textureinfo"&lt;BR&gt;&amp;nbsp;&amp;nbsp;xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;BR&gt;&amp;nbsp;&amp;nbsp;xsi:schemaLocation="http://xna.microsoft.com/textureinfo textureinfo.xsd"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Now if you open your XML file in a application that supports XSD (like Visual C# Express), you'll get validation squiggles. It doesn't perform a complete validation of the file, but it will catch most basic errors/typos. If you want to keep the XSD files in a separate directory, replace "textureinfo.xsd" in the "xsi:schemaLocation" attribute with a path+filename.&lt;/P&gt;
&lt;P align=center&gt;&lt;IMG src="http://blogs.msdn.com/photos/garykac/images/759301/original.aspx"&gt;&lt;/P&gt;
&lt;P&gt;Beyond making your code more manageable, there's another aspect to this code/data separation that can benefit your work: Your art assets become more shareable with others. If you're thinking "Why would I want to make it easier for people to steal my art?", try to step back and think about the XNA gaming community as a whole.&lt;/P&gt;
&lt;P&gt;While it means that others can more easily make use of your assets, it also means that you can more easily make use of the assets that others create. This sharing is crucial to developing and maintaining a thriving game development community. Yes, some people will "steal" and not give credit, but that sort of thing will happen no matter what you do (unless you don't release your game at all).&lt;/P&gt;
&lt;P&gt;As mentioned earlier, exposing your art like this makes it much easier to be replaced/updated. While this is obviously good for you, it can&amp;nbsp;also enable a modding community to build up around your game - people (even those with no programminng experience) can now take your game and make new skins without messing with the code. How cool would that be?&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=759249" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/garykac/archive/tags/XNA/default.aspx">XNA</category></item><item><title>Creating UI border elements in XNA</title><link>http://blogs.msdn.com/garykac/archive/2006/09/16/758576.aspx</link><pubDate>Sun, 17 Sep 2006 08:30:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:758576</guid><dc:creator>garykac</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/garykac/comments/758576.aspx</comments><wfw:commentRss>http://blogs.msdn.com/garykac/commentrss.aspx?PostID=758576</wfw:commentRss><description>&lt;P&gt;The XNAExtras.Border class provides a general border mechanism for UI elements. While currently only the XNAExtras.TextBox class makes use of it, future releases of XNAExtras will include Menus and perhaps some other elements that will be built on top of Borders.&lt;/P&gt;
&lt;P&gt;When creating borders, you can use the default border graphics (e.g., those that come with the TextBox demo) or you can&amp;nbsp;create your own&amp;nbsp;custom graphics. This post describes what you need to do to create and use your own custom borders.&lt;/P&gt;
&lt;P&gt;As an example, we'll make use of one of the borders included in the TextBoxDemo sample project. This project is part of the XNAExtras package, which you can download from &lt;A href="http://blogs.msdn.com/garykac/articles/749188.aspx"&gt;here&lt;/A&gt; if you don't already have it.&lt;/P&gt;
&lt;P&gt;The border image that we'll be examining is "border.png" - a simple 25x33 image that contains a single border. It's located in the "XNA Samples\TextBoxDemo\Content" folder and is shown in the following figure (with some markup denoting the different regions of the border image):&lt;/P&gt;
&lt;TABLE align=center&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;IMG src="http://blogs.msdn.com/photos/garykac/images/758274/original.aspx"&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;When designing a border image, you should&amp;nbsp;think of it as 9 separate regions that need to blend together smoothly: the four corners, four edges and the center.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The four corners are typically the largest and most distinctive part of any border. The corners are never stretched or scaled when they are drawn.&lt;/LI&gt;
&lt;LI&gt;The edges are drawn between two neighboring corners and stretch vertically or horizontally to make the border the correct size. As can be seen in "border.png", the edges do not need to be more than a single pixel wide or high.&lt;/LI&gt;
&lt;LI&gt;The center is typically a single pixel that defines the background color for the border. The center is stretched both horizontally and vertically to match the border size.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;So, now that you have a border image, what do you do with it? You can use the following code to create and display your border.&lt;/P&gt;
&lt;P&gt;First, set up your project. This process is the same for all XNA projects that use XNAExtras.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Create a new "Windows Game (XNA)" project and add all of the&amp;nbsp;XNAExtras source files&amp;nbsp;to it.&lt;/LI&gt;
&lt;LI&gt;Add a reference to System.Xml. To do this, right-click on the References folder in the Solution Explorer for your project. Select "Add Reference...". From the ".NET" tab, select "System.Xml" and then click the "Add" button.&lt;/LI&gt;
&lt;LI&gt;Add "using XNAExtras;" to the top of your source files with the other using statements.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Now you can start adding code to the main game class. Add the following member variable to your game class:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=#0000ff&gt;private&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;XSpriteManager&lt;/FONT&gt; m_sprites;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Add the following initialization code:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// create a sprite manager to manage the drawing&lt;BR&gt;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_sprites = &lt;FONT color=#000080&gt;new&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;XSpriteManager&lt;/FONT&gt;();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// load the texture that contains the border&lt;BR&gt;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_sprites.AddTexture(&lt;FONT color=#ff0000&gt;"tx_border"&lt;/FONT&gt;, &lt;FONT color=#ff0000&gt;"border.png"&lt;/FONT&gt;, 25, 33);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// define a border type from the texture&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&amp;nbsp;(use the default settings to init the border)&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_sprites.DefineBorder(&lt;FONT color=#ff0000&gt;"border_def"&lt;/FONT&gt;, &lt;FONT color=#ff0000&gt;"tx_border"&lt;/FONT&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;// instantiate the border and set its size&lt;BR&gt;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=#0000ff&gt;Border&lt;/FONT&gt; b = m_sprites.AddBorder(&lt;FONT color=#ff0000&gt;"border test"&lt;/FONT&gt;, &lt;FONT color=#ff0000&gt;"border_def"&lt;/FONT&gt;);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;b.SetDestRect(50,50,100,100);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Add the following initialization code after the call to InitializeComponent (or place it wherever you handle device resets):&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_sprites.Reset(graphics.GraphicsDevice);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;And finally, add the following to your Draw routine (between your BeginScene and your EndScene):&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_sprites.Draw();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Compile and run and you'll see a empty border on your screen. You'll need to have copied the "border.png" file into the same directory as the EXE or else the texture won't be found.&lt;/P&gt;
&lt;P&gt;Note that the code given above uses the default parameters to define the border, which works in this example because the texture contained only this one border sprite. The left, top, right and bottom values for the border were also automatically determined by taking the image size and dividing it in half and assuming that the center was 1x1 pixels in size.&lt;/P&gt;
&lt;P&gt;To have more control over the border creation parameters, you need to define the border using a Border.CreationParameters struct:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;FONT color=#0000ff&gt;Border&lt;/FONT&gt;.&lt;FONT color=#0000ff&gt;CreationParameters&lt;/FONT&gt; bcp = new &lt;FONT color=#0000ff&gt;Border&lt;/FONT&gt;.&lt;FONT color=#0000ff&gt;CreationParameters&lt;/FONT&gt;();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;bcp.strTexName = &lt;FONT color=#ff0000&gt;"tx_border"&lt;/FONT&gt;;&lt;FONT color=#008000&gt;// name of&amp;nbsp;texture with border&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;bcp.SetLocation(0, 0);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#008000&gt;// location of border image in texture&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;bcp.SetSize(25, 33);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#008000&gt;// size of border image&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;bcp.SetEdges(12, 16, 12, 16);&lt;FONT color=#008000&gt;// size of LTRB edges in texture&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;bcp.SetOrigin(4, 8);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#008000&gt;// border position&amp;nbsp;adjustment&lt;/FONT&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;m_sprites.DefineBorder(&lt;FONT color=#ff0000&gt;"border_def"&lt;/FONT&gt;, bcp);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;As a final&amp;nbsp;comment about borders,&amp;nbsp;note the SetOrigin line in the above example.&amp;nbsp;This parameter is used to adjust the position of the border around the rectangle. Compare the borders in the next image:&lt;/P&gt;
&lt;TABLE align=center&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;IMG src="http://blogs.msdn.com/photos/garykac/images/758339/original.aspx"&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;The left column shows the border and the right column shows the same border with the content rectangle blanked out to make it easier to see. All of the rectangles are 100x100, but the bottom row used the SetOrigin method shown above to pull the border closer to the rectangle.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=758576" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/garykac/archive/tags/XNA/default.aspx">XNA</category></item><item><title>XNAExtras build 0916 release</title><link>http://blogs.msdn.com/garykac/archive/2006/09/16/757867.aspx</link><pubDate>Sat, 16 Sep 2006 20:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:757867</guid><dc:creator>garykac</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/garykac/comments/757867.aspx</comments><wfw:commentRss>http://blogs.msdn.com/garykac/commentrss.aspx?PostID=757867</wfw:commentRss><description>&lt;P&gt;This release includes a bunch of small enhancements and bug fixes. The only major class addition is XSpriteGroup, which allows you to manipulate a group of sprites as a single unit.&lt;/P&gt;
&lt;P&gt;From the release notes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(XML Schema) Added XML schema definition (XSD) files for bitmap and texture files&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(BMFontGen) Fixed bug where custom glyphs couldn't replace chars that didn't exist in font&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(BitmapFont) Added Dispose method&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(BitmapFont) Fixed TextBox to format the string only once&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(BitmapFont) Allow fonts to be loaded from embedded resources&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(BitmapFont/XSpriteManager) Changed GetXMLAttribute to not throw exceptions&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(XSpriteManager) Changed sprites to sort by order of creation when at the same depth&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(XSpriteBase) Added Visible property&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(XSprite) Added SetTexture method&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(XSprite) Expose sprite alpha value directly&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;(TexturePool) Fixed bug in AddTexture(string,Color) where the texture wasn't being created if the GraphicsDevice already existed&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Thanks to everyone (and especially to David Zakar (DMZ), redwyre and Martin Szinger) who took the time to send comments, bug reports and feature requests.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;[&lt;STRONG&gt;Update&lt;/STRONG&gt;: Oops! Björn points out that I forgot the link to the updated version. The link to the latest version is &lt;A href="http://blogs.msdn.com/garykac/articles/749188.aspx"&gt;here&lt;/A&gt;.]&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=757867" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/garykac/archive/tags/XNA/default.aspx">XNA</category></item><item><title>"But I don't want to have to worry about sprite depths..."</title><link>http://blogs.msdn.com/garykac/archive/2006/09/14/749911.aspx</link><pubDate>Fri, 15 Sep 2006 02:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:749911</guid><dc:creator>garykac</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/garykac/comments/749911.aspx</comments><wfw:commentRss>http://blogs.msdn.com/garykac/commentrss.aspx?PostID=749911</wfw:commentRss><description>&lt;P&gt;Well, you don't have to really. Or maybe you're already dealing with depth and you don't realize it.&lt;/P&gt;
&lt;P&gt;To recap: There are two ways of controlling sprite "depth". The first is to use the SpriteBatch.Draw methods that allow a layerDepth parameter. The second is just to draw your sprites at the same depth, but from back to front.&lt;/P&gt;
&lt;P&gt;The layerDepth approach is nice when you have lots of sprites at different depths, or when they're changing depths regularly. You give each sprite&amp;nbsp;a depth and then forget about it. This allows you to draw your objects ordered by type (first the map, then the player, then the objects, ...) as opposed to by how far they are&amp;nbsp;into the screen. &lt;/P&gt;
&lt;P&gt;The simpler approach of drawing from back to front is seen when&amp;nbsp;you draw your background first, then your objects and then finish up with your overlay and UI elements.&amp;nbsp;Basically, you've hardcoded your back-to-front sort order in your code. Not very flexible perhaps, but perfectly appropriate for a large number of games. And you don't have to worry about depth at all - beyond the coarse background/objects/overlay distinction.&lt;/P&gt;
&lt;P&gt;XSpriteManager supports both approaches. If you give it a depth, the right thing will happen - and the sprites will be kept in sorted order so that they render quickly. But if&amp;nbsp;you don't want to set the depth, you can just&amp;nbsp;add sprites and they will be rendered in the order that they&amp;nbsp;were created. By default, XSprites are drawn at depth=0.0 (which is closest to the screen).&lt;/P&gt;
&lt;P&gt;The motivation for all this is the game that I'm working on (big surprise there, eh?). It's a basic tile-based isometric RPG which had a definite need for a class to manage all the sprites. To handle the map tiles, I wanted to put each row at a different depth and then place the player (and NPCs) at depths between the rows.&lt;/P&gt;
&lt;P&gt;I'll try to talk more about this game once I get a few more basic classes finished up.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=749911" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/garykac/archive/tags/XNA/default.aspx">XNA</category></item><item><title>XNAExtras : tools and classes for XNA</title><link>http://blogs.msdn.com/garykac/archive/2006/09/10/747468.aspx</link><pubDate>Mon, 11 Sep 2006 08:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:747468</guid><dc:creator>garykac</dc:creator><slash:comments>12</slash:comments><comments>http://blogs.msdn.com/garykac/comments/747468.aspx</comments><wfw:commentRss>http://blogs.msdn.com/garykac/commentrss.aspx?PostID=747468</wfw:commentRss><description>&lt;P&gt;In order to simplify releases, I'm collecting all of my XNA tools, classes and sample code into a single XNAExtras package. You can find a link to the latest version of XNAExtras &lt;A href="http://blogs.msdn.com/garykac/articles/749188.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;This first XNAExtras release contains updated versions of BMFontGen and BitmapFont:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;BMFontGen&lt;/STRONG&gt; :&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;Added font face name, size and style info to XML font descriptor file.&lt;BR&gt;Added option&amp;nbsp;to prevent custom glyphs from being tinted when drawing colored text.&lt;BR&gt;Fixed crash when cancelling the font select dialog (oops!).&lt;BR&gt;Changed code to prevent substitute fonts being used&amp;nbsp;when the requested font is unavailable.&lt;BR&gt;Changed "origin" attribute in font XML files to "loc" (location) since this is a better description and is more consistent with usage in sprite/texture XML files. Fonts created with "origin" attribute are still supported.&lt;BR&gt;Removed support for ClearType anti-aliasing.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;BitmapFont&lt;/STRONG&gt; :&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;Fixed path problem&amp;nbsp;whereby font image files weren't found if the font was in a subdirectory.&lt;BR&gt;Changed GlyphInfo struct (in BitmapFont) to use bytes/sbytes instead of ints.&lt;BR&gt;Added support for new features in XML font file.&lt;BR&gt;Added TextBox method to format left, center or right-aligned text in a rectangle.&lt;BR&gt;Added Save/RestoreState methods to save and restore the font rendering state.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;Thanks to David Wyand, Thijs Kruithof (Gleoi), Jim Welch and Roger Bocksnick for their comments/suggestions.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;In addition,&amp;nbsp;a few extra classes (and associated demos) have been added:&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P&gt;&lt;STRONG&gt;TextBox&lt;/STRONG&gt; : Class to manage more complex text rendering, includes support for rendering text borders to create UI elements. Makes use of BitmapFont and Border. (TextBox.cs)&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Border&lt;/STRONG&gt; : Class to draw sprite-based borders around rectangles. Makes use of XSprite. (Border.cs)&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;XSprite&lt;/STRONG&gt; : Classes to manage sprites. Supports shared textures, animated sprites, different framerates for each sprite, keeps sprites sorted by depth (so that transparency works correctly) and allows sprites to be loaded from an XML descriptor file. (XSprite.cs, XSpriteBase.cs, XSpriteManager.cs, TexturePool.cs)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note that I wasn't originally intending to include the XSprite classes with this release because there are still a few features that I wanted to add and I still need to finish the sprite demo to make it more interesting. However, because the Border class relies on it, you get to see a preview of these classes.&lt;/P&gt;
&lt;P&gt;I'll probably talk about these classes and demos more in upcoming posts. As always, comments, suggestions and bug reports are welcome.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=747468" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/garykac/archive/tags/XNA/default.aspx">XNA</category></item><item><title>The cost of SpriteBlendMode.AlphaBlend and the SpriteSortOptions</title><link>http://blogs.msdn.com/garykac/archive/2006/09/10/748779.aspx</link><pubDate>Sun, 10 Sep 2006 21:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:748779</guid><dc:creator>garykac</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/garykac/comments/748779.aspx</comments><wfw:commentRss>http://blogs.msdn.com/garykac/commentrss.aspx?PostID=748779</wfw:commentRss><description>&lt;P&gt;The SpriteBatch.Begin method has a couple of parameters that control how the sprites are rendered on the screen. Most people are aware of SpriteBlendMode.AlphaBlend, but for transparency to work correctly, you&amp;nbsp;need to ensure that your sprites are being drawn back to front.&lt;/P&gt;
&lt;P&gt;Now, if you're just using transparency to&amp;nbsp;knock the background out of an image, then you&amp;nbsp;might&amp;nbsp;not notice any problems&amp;nbsp;- even if you draw your sprites in the wrong order. In this case the effect&amp;nbsp;is localized to the edges of your objects where they're less likely to draw attention.&lt;/P&gt;
&lt;P&gt;But if you have large regions of transparency, the&amp;nbsp;impact of not drawing back to front&amp;nbsp;can be quite noticeable.&lt;/P&gt;
&lt;TABLE align=center&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;IMG src="http://blogs.msdn.com/photos/garykac/images/748687/original.aspx"&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;The above image shows what happens when&amp;nbsp;5 circles (white with alpha=68%) are drawn in the wrong order and the correct order. On the left side, the front circle is drawn first so it is blended with the background image (resulting in the blue outline) and the depth buffer prevents the back circles from being drawn behind the front circle. The right side shows the desired effect, where the front circle is drawn last and is blended correctly with the back circles.&lt;/P&gt;
&lt;P&gt;This is where SpriteSortOptions comes into the picture (so to speak). With this option, you draw your sprites in any order (but at the correct depth) and the right thing will happen.&lt;/P&gt;
&lt;P dir=ltr style="MARGIN-RIGHT: 0px"&gt;So the next questions&amp;nbsp;are : How expensive is it to have the SpriteBatch class manage our sprite sort order? Is&amp;nbsp;it&amp;nbsp;better to sort the sprites once (in&amp;nbsp;your app) and then draw them in the correct order?&lt;/P&gt;
&lt;P&gt;To test this, I wrote a simple app that creates a bunch of 64x64 sprites and places them at random depths and locations. I then plotted the FPS as I increased the&amp;nbsp;number of sprites:&lt;/P&gt;
&lt;TABLE align=center&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;IMG src="http://blogs.msdn.com/photos/garykac/images/748759/original.aspx"&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;The&amp;nbsp;lines in this graph are for &lt;FONT color=#ff0000&gt;SpriteBlendMode.None&lt;/FONT&gt; (in &lt;FONT color=#ff0000&gt;red&lt;/FONT&gt;), &lt;FONT color=#006400&gt;SpriteBlendMode.AlphaBlend&lt;/FONT&gt; (in &lt;FONT color=#006400&gt;green&lt;/FONT&gt;), and &lt;FONT color=#000080&gt;AlphaBlend with &lt;/FONT&gt;&lt;FONT color=#000080&gt;SpriteSortOptions.BackToFront&lt;/FONT&gt; (in &lt;FONT color=#000080&gt;blue&lt;/FONT&gt;). The &lt;FONT color=#808080&gt;gray&lt;/FONT&gt; line at the top is for SpriteSortOptions.FrontToBack, which is (surprisingly) faster than SpriteBlendMode.None but&amp;nbsp;blends the sprites incorrectly. &lt;EM&gt;[Reminder: these data points are from the beta XNA release]&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;If you sort your own sprites and draw them in the correct order, then you get to use the green line. For large numbers (&amp;gt; 500) of sprites, this can be a big win.&lt;/P&gt;
&lt;P&gt;Having SpriteBatch sort your sprites for you limits you to around&amp;nbsp;400&amp;nbsp;sprites (64x64) before it starts to impact the framerate. If you're content with 30 fps, then you're good up to&amp;nbsp;1000 sprites.&lt;/P&gt;
&lt;P&gt;Of course,&amp;nbsp;if you don't mind&amp;nbsp;having your sprites blended incorrectly, you&amp;nbsp;can have even more.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;[Note that the beta XNA release sorts the sprites front to back when you specify SpriteSortOptions.BackToFront. You need to get the bizarro-world version of XNA to have BackToFront actually mean back to front. Or wait for the release version, I imagine. ^_^&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Fortunately, FrontToBack in the beta means back to front, so you can use that as a workaround. In this post, I've applied the workaround&amp;nbsp;so when I say "BackToFront" I'm really using SpriteSortOptions.FrontToBack (and vice versa).]&lt;/EM&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=748779" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/garykac/archive/tags/XNA/default.aspx">XNA</category></item><item><title>360 Controller Demo</title><link>http://blogs.msdn.com/garykac/archive/2006/09/01/735470.aspx</link><pubDate>Fri, 01 Sep 2006 19:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:735470</guid><dc:creator>garykac</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/garykac/comments/735470.aspx</comments><wfw:commentRss>http://blogs.msdn.com/garykac/commentrss.aspx?PostID=735470</wfw:commentRss><description>&lt;P&gt;Don't you hate it when you have a little demo that you're thinking of releasing and someone comes around and and does basically what you wanted to do, only better? How 'bout if it's a whole lot better?&lt;/P&gt;
&lt;P&gt;Well, &lt;A href="http://blogs.msdn.com/pstubbs/"&gt;Paul&lt;/A&gt; just did that to me with his &lt;A href="http://blogs.msdn.com/pstubbs/archive/2006/08/31/733031.aspx"&gt;360 Controller Test&lt;/A&gt; sample app. He took his original app (which used&amp;nbsp;C#, MDX, XInput &amp;amp; Windows Forms) and converted it to XNA in a few hours. It&amp;nbsp;gives graphic feedback of the controller state and makes it rumble when the triggers are pulled.&lt;/P&gt;
&lt;P&gt;On the upside, it means that I can focus on other things instead of polishing and wrapping up my code...&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=735470" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/garykac/archive/tags/XNA/default.aspx">XNA</category></item><item><title>Creating and using bitmap fonts in XNA</title><link>http://blogs.msdn.com/garykac/archive/2006/08/30/728521.aspx</link><pubDate>Thu, 31 Aug 2006 06:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:728521</guid><dc:creator>garykac</dc:creator><slash:comments>19</slash:comments><comments>http://blogs.msdn.com/garykac/comments/728521.aspx</comments><wfw:commentRss>http://blogs.msdn.com/garykac/commentrss.aspx?PostID=728521</wfw:commentRss><description>&lt;P&gt;As mentioned in a&amp;nbsp;&lt;A href="http://blogs.msdn.com/garykac/archive/2006/08/29/726222.aspx"&gt;previous post&lt;/A&gt;, there is a clear need for a bitmap font generator that provides proper Unicode support.&lt;/P&gt;
&lt;P&gt;To address this need, I created BMFontGen.exe. This program can generate a bitmap font from any of the fonts currently installed on your system and it provides a variety of options for controlling which&amp;nbsp;glyphs get placed in the font and how they appear. More details about the tool (including a download link) are given in&amp;nbsp;&lt;A href="http://blogs.msdn.com/garykac/articles/732007.aspx"&gt;this document&lt;/A&gt;, but for our purposes it suffices to know that&amp;nbsp;BMFontGen takes a font name and a font size and produces an XML file (containing the font description) and a collection of PNG files (that contain the glyph bitmaps).&lt;/P&gt;
&lt;P&gt;To use these fonts in an XNA game, you need some code that can load these files and let you draw a string of text on the screen. To fill this role,&amp;nbsp;I created the BitmapFont class. This class handles the font loading and exposes a set of DrawString methods that do what you would expect them to do.&lt;/P&gt;
&lt;P&gt;To demonstrate the class in action, I've created a simple demo app (attached to this post - see &lt;A href="http://blogs.msdn.com/garykac/attachment/728521.ashx"&gt;link&lt;/A&gt; at bottom) which I've cleverly named "BitmapFontDemo". Here is a screenshot from the app that shows off some of the capabilities of the font renderer.&lt;/P&gt;
&lt;P align=center&gt;&lt;A href="http://blogs.msdn.com/photos/garykac/images/732782/original.aspx"&gt;&lt;IMG src="http://blogs.msdn.com/photos/garykac/images/732779/original.aspx"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;The BitmapFont class is intended to provide basic text rendering services only, so don't expect it to handle linebreaks or format text in a rectangle or provide any other advanced text options. However, I'll be adding functionality to it as time goes on, and I also intend to&amp;nbsp;release other game support classes that build upon the base functionality provided by BitmapFont.&lt;/P&gt;
&lt;P&gt;This is the first release for this tool, so let me know if you find this useful or if&amp;nbsp;you think there're features missing. I'm curious to see games that make use of these fonts (even if I can't read them ^_^).&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=728521" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/garykac/attachment/728521.ashx" length="78132" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/garykac/archive/tags/XNA/default.aspx">XNA</category></item><item><title>Finally...</title><link>http://blogs.msdn.com/garykac/archive/2006/08/30/731890.aspx</link><pubDate>Wed, 30 Aug 2006 18:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:731890</guid><dc:creator>garykac</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/garykac/comments/731890.aspx</comments><wfw:commentRss>http://blogs.msdn.com/garykac/commentrss.aspx?PostID=731890</wfw:commentRss><description>&lt;P&gt;&lt;A href="http://www.microsoft.com/downloads/details.aspx?familyid=21e979e3-b8ae-4ea6-8e65-393ea7684d6c&amp;amp;displaylang=en"&gt;Microsoft XNA Game Studio Express (Beta)&lt;/A&gt; is now available!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=731890" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/garykac/archive/tags/XNA/default.aspx">XNA</category></item></channel></rss>