<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Blog of Zachary Snow &#187; XNA</title>
	<atom:link href="http://zacharysnow.net/tag/xna/feed/" rel="self" type="application/rss+xml" />
	<link>http://zacharysnow.net</link>
	<description></description>
	<lastBuildDate>Tue, 20 Dec 2011 19:41:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>What is Snowball and what do I want to do with it?</title>
		<link>http://zacharysnow.net/2011/10/16/what-is-snowball-and-what-do-i-want-to-do-with-it/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=what-is-snowball-and-what-do-i-want-to-do-with-it</link>
		<comments>http://zacharysnow.net/2011/10/16/what-is-snowball-and-what-do-i-want-to-do-with-it/#comments</comments>
		<pubDate>Sun, 16 Oct 2011 18:30:47 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[SlimDX]]></category>
		<category><![CDATA[Snowball]]></category>
		<category><![CDATA[2D]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[codeplex]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[slimdx]]></category>
		<category><![CDATA[snowball]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/?p=462</guid>
		<description><![CDATA[I originally got the idea for Snowball after working with the Xna Framework. The Xna Framework is a good piece of software for what it is but there are some things about which I just do not agree with: The &#8230; <a href="http://zacharysnow.net/2011/10/16/what-is-snowball-and-what-do-i-want-to-do-with-it/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I originally got the idea for Snowball after working with the Xna Framework. The Xna Framework is a good piece of software for what it is but there are some things about which I just do not agree with:</p>
<ul>
<li>The content pipeline only works with content in the serialized .xnb format.</li>
<li>There are certain content types which can only be loaded via the content pipeline.</li>
<li>Certain features don&#8217;t exist on the PC because they don&#8217;t exist on the XBox or Windows Phone 7.</li>
</ul>
<p>Xna was designed as an abstraction layer for all the 3 platforms mentioned in the last point, so that one is somewhat understandable. I don&#8217;t want to write games for my XBox right now though, so why should things like drawing lines not be available to me?</p>
<p>With these points in mind I started working on <a href="http://snowball.codeplex.com/">Snowball</a>. It&#8217;s designed to be an Xna like framework for making 2D games. It uses SlimDX on the backend, but that is completely abstracted away from consumers of the framework. What I want to do is design the API so that the backend can be swapped out <strong>somewhat</strong> painlessly.</p>
<p>I still have a ways to go before I will consider it a version 1.0 release. As of this writing, I&#8217;m transitioning to more of a ContentLoader class style for loading your game&#8217;s content. Any resource type from within the framework can be loaded by hand if you want, the ContentLoader class will just make it easier. After that I have a few other features like GamePad and Music which I would like to implement before saying I have a Beta type release.</p>
<p>The future after that is up in the air. I would love to try and have different implementations of the API for Xna and/or OpenTK.</p>
<p>I recommend for anyone who is interested as to why an API designer choose to implement the API in the way they did to try it for themselves. I have learned many things from this project including why certain design decisions were made by the Xna Framework team. </p>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2011/10/16/what-is-snowball-and-what-do-i-want-to-do-with-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>500 Downloads of the Same Game</title>
		<link>http://zacharysnow.net/2010/06/09/500-downloads-of-the-same-game/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=500-downloads-of-the-same-game</link>
		<comments>http://zacharysnow.net/2010/06/09/500-downloads-of-the-same-game/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 20:17:28 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[XNA]]></category>
		<category><![CDATA[codeplex]]></category>
		<category><![CDATA[SameGameXna]]></category>
		<category><![CDATA[WinForms]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/2010/06/09/500-downloads-of-the-same-game/</guid>
		<description><![CDATA[My little Xna game that I wrote nearly 2 years ago reached the 500 downloads mark (binaries and source) the other day. With that said, I&#8217;d like to say that I&#8217;m working on version 2.0. In version 2.0 I&#8217;m going &#8230; <a href="http://zacharysnow.net/2010/06/09/500-downloads-of-the-same-game/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>My little Xna game that I wrote nearly 2 years ago reached the 500 downloads mark (binaries and source) the other day. With that said, I&#8217;d like to say that I&#8217;m working on version 2.0.</p>
<p>In version 2.0 I&#8217;m going to make the code more event driven. The old code uses the Xna Game class and in the new version I&#8217;ll be making it WinForms based. Almost a complete rewrite.</p>
<p>My work so far is available through SVN on the project&#8217;s <a href="http://samegamexna.codeplex.com/">Codeplex page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2010/06/09/500-downloads-of-the-same-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drawing Rectangles with SpriteBatch</title>
		<link>http://zacharysnow.net/2010/03/29/drawing-rectangles-with-spritebatch/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=drawing-rectangles-with-spritebatch</link>
		<comments>http://zacharysnow.net/2010/03/29/drawing-rectangles-with-spritebatch/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 17:14:25 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/2010/03/29/drawing-rectangles-with-spritebatch/</guid>
		<description><![CDATA[Just a quick code snippet which adds an extension method for drawing Rectangles to SpriteBatch: public static class SpriteBatchHelper { static Texture2D pixel; private static void LoadPixel(GraphicsDevice graphicsDevice) { if(pixel == null) { pixel = new Texture2D(graphicsDevice, 1, 1); pixel.SetData&#60;Color&#62;(new &#8230; <a href="http://zacharysnow.net/2010/03/29/drawing-rectangles-with-spritebatch/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Just a quick code snippet which adds an extension method for drawing Rectangles to SpriteBatch:</p>
<pre name="code" class="c#">
public static class SpriteBatchHelper
{
	static Texture2D pixel;

	private static void LoadPixel(GraphicsDevice graphicsDevice)
	{
		if(pixel == null)
		{
			pixel = new Texture2D(graphicsDevice, 1, 1);
			pixel.SetData&lt;Color&gt;(new Color[] { Color.White });
		}
	}

	public static void DrawRectangle(this SpriteBatch spriteBatch, Rectangle rectangle, Color color)
	{
		LoadPixel(spriteBatch.GraphicsDevice);
		spriteBatch.Draw(pixel, rectangle, color);
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2010/03/29/drawing-rectangles-with-spritebatch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculating an angle from a Vector2</title>
		<link>http://zacharysnow.net/2009/02/28/calculating-an-angle-from-a-vector2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=calculating-an-angle-from-a-vector2</link>
		<comments>http://zacharysnow.net/2009/02/28/calculating-an-angle-from-a-vector2/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 11:30:11 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Vectors]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://snowxna.wordpress.com/?p=45</guid>
		<description><![CDATA[When you need to calculate an angle from a Vector2 structure, you can use this piece of code: public static class Vector2Helper { public static float CalculateAngle(Vector2 v) { float angle = 0.0f; if(v != Vector2.Zero) { v.Normalize(); angle = &#8230; <a href="http://zacharysnow.net/2009/02/28/calculating-an-angle-from-a-vector2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When you need to calculate an angle from a Vector2 structure, you can use this piece of code:</p>
<pre name="code" class="c#">
public static class Vector2Helper
{
	public static float CalculateAngle(Vector2 v)
	{
		float angle = 0.0f;

		if(v != Vector2.Zero)
		{
			v.Normalize();

			angle = (float)Math.Acos(v.Y);

			if(v.X &lt; 0.0f)
			angle = -angle;
		}

		return angle;
	}
}
</pre>
<p>I used this to calculate an angle from the Vector2 of the Left Stick.</p>
<p>The original credit for this source code comes from <a href="http://xnagamer.spaces.live.com/blog/cns!EC20BAAE6808B682!139.entry">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2009/02/28/calculating-an-angle-from-a-vector2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SpriteSheet Class</title>
		<link>http://zacharysnow.net/2009/01/09/spritesheet-class/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=spritesheet-class</link>
		<comments>http://zacharysnow.net/2009/01/09/spritesheet-class/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 11:41:56 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[SpriteSheet]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://snowxna.wordpress.com/?p=33</guid>
		<description><![CDATA[I&#8217;ve been talking with a guy on the creator forums lately about SpriteSheets and so I decided it might be a good idea to post my SpriteSheet class. It&#8217;s very simple. Only reads sprites from left to right and assumes &#8230; <a href="http://zacharysnow.net/2009/01/09/spritesheet-class/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been talking with a guy on the creator forums lately about SpriteSheets and so I decided it might be a good idea to post my SpriteSheet class.</p>
<p>It&#8217;s very simple. Only reads sprites from left to right and assumes all Sprites are the same width and height.</p>
<pre name="code" class="csharp">
#region Using
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace Snow.Xna.Graphics
{
	///
<summary>
	/// Spritesheet class.
	/// </summary>

	public class SpriteSheet
	{
		#region Fields

		string name;

		Texture2D texture;

		Rectangle[] rectangles;

		int spriteWidth, spriteHeight;

		#endregion

		#region Properties

		///
<summary>
		/// The name of this SpriteSheet.
		/// </summary>

		public string Name
		{
			get { return name; }
		}

		///
<summary>
		/// The texture for this SpriteSheet.
		/// </summary>

		public Texture2D Texture
		{
			get { return texture; }
		}

		///
<summary>
		/// Returns a rectangle for a sprite in the SpriteSheet.
		/// </summary>

		///
<param name="i">index</param>
		/// <returns></returns>
		public Rectangle this[int i]
		{
			get { return rectangles[i]; }
		}

		///
<summary>
		/// The number of sprites in this SpriteSheet.
		/// </summary>

		public int Count
		{
			get { return rectangles.Length; }
		}

		///
<summary>
		/// The width of the texture.
		/// </summary>

		public int Width
		{
			get { return texture.Width; }
		}

		///
<summary>
		/// The width of each sprite in the SpriteSheet.
		/// </summary>

		public int SpriteWidth
		{
			get { return spriteWidth; }
		}

		///
<summary>
		/// The height of the texture.
		/// </summary>

		public int Height
		{
			get { return texture.Height; }
		}

		///
<summary>
		/// The height of each sprite in the SpriteSheet.
		/// </summary>

		public int SpriteHeight
		{
			get { return spriteHeight; }
		}

		#endregion

		///
<summary>
		/// Create a new SpriteSheet and determine the number of sprites in the sheet.
		/// </summary>

		///
<param name="texture"></param>
		///
<param name="spriteWidth">Width of each sprite.</param>
		///
<param name="spriteHeight">Height of each sprite.</param>
		public SpriteSheet(string name, Texture2D texture, int spriteWidth, int spriteHeight)
			: this(name, texture, spriteWidth, spriteHeight, 0)
		{
		}

		///
<summary>
		/// Create a new SpriteSheet.
		/// </summary>

		///
<param name="texture"></param>
		///
<param name="spriteWidth">Width of each sprite.</param>
		///
<param name="spriteHeight">Height of each sprite.</param>
		///
<param name="count">The number of sprites in the sheet.</param>
		public SpriteSheet(string name, Texture2D texture, int spriteWidth, int spriteHeight, int count)
		{
			this.name = name;
			this.texture = texture;
			this.spriteWidth = spriteWidth;
			this.spriteHeight = spriteHeight;

			if(count == 0)
			{
				int numX = texture.Width / spriteWidth;
				int numY = texture.Height / spriteHeight;

				rectangles = new Rectangle[numX * numY];
			}
			else
			{
				rectangles = new Rectangle[count];
			}

			int x = 0, y = 0;
			for(int i = 0; i < rectangles.Length; i++)
			{
				rectangles[i] = new Rectangle(x, y, spriteWidth, spriteHeight);

				x += spriteWidth;
				if(x >= texture.Width)
				{
					x = 0;
					y += spriteHeight;
				}
			}
		}

		public static implicit operator Texture2D(SpriteSheet spriteSheet)
		{
			return spriteSheet.Texture;
		}
	}
}
</pre>
<p>You can create a new SpriteSheet and use it like this:</p>
<p><code></p>
<pre name="code" class="c#">
SpriteSheet spriteSheet = new SpriteSheet("tiles", Content.Load<texture2D>("tiles"), 64, 64);

spriteBatch.Begin();

spriteBatch.Draw(spriteSheet,
		        new Rectangle(0, 0, spriteSheet.SpriteWidth, spriteSheet.SpriteHeight),
			spriteSheet[0],
			Color.White);

spriteBatch.End();
</pre>
<p></code></p>
<p>Which loads a spritesheet with sprites of size 64&#215;64. It then draws the first Sprite in the SpriteSheet. You of course wouldn&#8217;t want to load the spritesheet every frame as well.</p>
<p>Feel free to use this code without restriction.</p>
<p><strong>Edit:</strong> I copied and pasted the second piece of code from somewhere else so I fixed two typos.</p>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2009/01/09/spritesheet-class/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Colors and Hex</title>
		<link>http://zacharysnow.net/2008/12/20/colors-and-hex/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=colors-and-hex</link>
		<comments>http://zacharysnow.net/2008/12/20/colors-and-hex/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 23:05:37 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[hex]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://snowxna.wordpress.com/?p=21</guid>
		<description><![CDATA[I recently needed to write out Color(s) as an xml attribute. I wrote 2 methods to read and write the Color(s) as Hex strings. Here ya go: namespace Snow.Xna.Graphics { public static class ColorHelper { private static char[] _hexDigits = &#8230; <a href="http://zacharysnow.net/2008/12/20/colors-and-hex/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently needed to write out Color(s) as an xml attribute. I wrote 2 methods to read and write the Color(s) as Hex strings. Here ya go:</p>
<pre name="code" class="c#">
namespace Snow.Xna.Graphics
{
	public static class ColorHelper
	{
		private static char[] _hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

		public static string ToHexString(Color color)
		{
			byte[] bytes = new byte[4];

			bytes[0] = color.A;
			bytes[1] = color.R;
			bytes[2] = color.G;
			bytes[3] = color.B;

			char[] chars = new char[8];

			for(int i = 0; i < 4; i++)
			{
				int b = bytes[i];
				chars[i * 2] = _hexDigits[b >> 4];
				chars[i * 2 + 1] = _hexDigits[b &#038; 0xF];
			}

			return new string(chars);
		}

		private static byte HexDigitToByte(char c)
		{
			switch(c)
			{
				case '0': return (byte)0;
				case '1': return (byte)1;
				case '2': return (byte)2;
				case '3': return (byte)3;
				case '4': return (byte)4;
				case '5': return (byte)5;
				case '6': return (byte)6;
				case '7': return (byte)7;
				case '8': return (byte)8;
				case '9': return (byte)9;
				case 'A': return (byte)10;
				case 'B': return (byte)11;
				case 'C': return (byte)12;
				case 'D': return (byte)13;
				case 'E': return (byte)14;
				case 'F': return (byte)15;
			}

			return (byte)0;
		}

		public static Color FromHexString(string hex)
		{
			if( hex.Length != 8 )
				return Color.Black;

			int a = (HexDigitToByte(hex[0]) << 4) + HexDigitToByte(hex[1]);
			int r = (HexDigitToByte(hex[2]) << 4) + HexDigitToByte(hex[3]);
			int g = (HexDigitToByte(hex[4]) << 4) + HexDigitToByte(hex[5]);
			int b = (HexDigitToByte(hex[6]) << 4) + HexDigitToByte(hex[7]);

			return new Color((byte)r, (byte)g, (byte)b, (byte)a);
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2008/12/20/colors-and-hex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XNExtensions</title>
		<link>http://zacharysnow.net/2008/12/08/xnextensions/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=xnextensions</link>
		<comments>http://zacharysnow.net/2008/12/08/xnextensions/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 11:30:30 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://snowxna.wordpress.com/?p=9</guid>
		<description><![CDATA[Nick Gravelyn has released an open source set of C# extension methods for use with Xna. See the post here for more information. http://www.nickontech.com/2008/12/new-open-source-project-time/]]></description>
			<content:encoded><![CDATA[<p>Nick Gravelyn has released an open source set of C# extension methods for use with Xna. See the post <a href="http://www.nickontech.com/2008/12/new-open-source-project-time/">here</a> for more information.</a></p>
<p><a href="http://www.nickontech.com/2008/12/new-open-source-project-time/">http://www.nickontech.com/2008/12/new-open-source-project-time/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2008/12/08/xnextensions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

