diff --git a/axios/Axios_settings.cs b/axios/Axios_settings.cs
index 1b826a0..959d509 100644
--- a/axios/Axios_settings.cs
+++ b/axios/Axios_settings.cs
@@ -62,6 +62,12 @@
* 1.0.1.3 - 4/7/2012
* - Adding a check in the AxiosTimer update to only tick if the game is active
*
+ * 1.0.1.4 - 4/27/2012
+ * - Merging the new GSM
+ *
+ * 1.0.1.5 - 5/5/2012
+ * - Adding SplitFlat extension for Texture2D
+ *
*/
using System.Reflection;
diff --git a/axios/Engine/Extensions/Texture2D.cs b/axios/Engine/Extensions/Texture2D.cs
index 45a6ca3..441557e 100644
--- a/axios/Engine/Extensions/Texture2D.cs
+++ b/axios/Engine/Extensions/Texture2D.cs
@@ -132,6 +132,54 @@ namespace Axios.Engine.Extenions
return r;
}
+ /// http://gamedev.stackexchange.com/questions/11584/xna-splitting-one-large-texture-into-an-array-of-smaller-textures
+ ///
+ /// Splits a texture into an array of smaller textures of the specified size.
+ ///
+ /// The texture to be split into smaller textures
+ /// The width of each of the smaller textures that will be contained in the returned array.
+ /// The height of each of the smaller textures that will be contained in the returned array.
+ public static Texture2D[] SplitFlat(this Texture2D original, int partWidth, int partHeight, out int xCount, out int yCount)
+ {
+ yCount = original.Height / partHeight; //+ (partHeight % original.Height == 0 ? 0 : 1);//The number of textures in each horizontal row
+ xCount = original.Width / partWidth; //+(partWidth % original.Width == 0 ? 0 : 1);//The number of textures in each vertical column
+ Texture2D[] r = new Texture2D[xCount * yCount];//Number of parts = (area of original) / (area of each part).
+ int dataPerPart = partWidth * partHeight;//Number of pixels in each of the split parts
+
+ //Get the pixel data from the original texture:
+ Color[] originalData = new Color[original.Width * original.Height];
+ original.GetData(originalData);
+
+ int index = 0;
+ for (int y = 0; y < yCount * partHeight; y += partHeight)
+ for (int x = 0; x < xCount * partWidth; x += partWidth)
+ {
+ //The texture at coordinate {x, y} from the top-left of the original texture
+ Texture2D part = new Texture2D(original.GraphicsDevice, partWidth, partHeight);
+ //The data for part
+ Color[] partData = new Color[dataPerPart];
+
+ //Fill the part data with colors from the original texture
+ for (int py = 0; py < partHeight; py++)
+ for (int px = 0; px < partWidth; px++)
+ {
+ int partIndex = px + py * partWidth;
+ //If a part goes outside of the source texture, then fill the overlapping part with Color.Transparent
+ if (y + py >= original.Height || x + px >= original.Width)
+ partData[partIndex] = Color.Transparent;
+ else
+ partData[partIndex] = originalData[(x + px) + (y + py) * original.Width];
+ }
+
+ //Fill the part with the extracted data
+ part.SetData(partData);
+ //Stick the part in the return array:
+ r[index++] = part;
+ }
+ //Return the array of parts.
+ return r;
+ }
+
/// http://forums.create.msdn.com/forums/t/79258.aspx
///
/// Combines one texture with another