From e86a1f887c7bfdf692a70f1e08be0a087ad0a8ab Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Sat, 5 May 2012 23:18:31 -0500 Subject: [PATCH] Removing uneeded Game Screen check Adding SplitFlat that takes in offsets --- axios/Engine/Extensions/Texture2D.cs | 48 +++++++++++++++++++++++++ axios/ScreenSystem/PhysicsGameScreen.cs | 7 ++-- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/axios/Engine/Extensions/Texture2D.cs b/axios/Engine/Extensions/Texture2D.cs index 441557e..cab554a 100644 --- a/axios/Engine/Extensions/Texture2D.cs +++ b/axios/Engine/Extensions/Texture2D.cs @@ -180,6 +180,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, int offsetWidth, int offsetHeight, 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 + offsetHeight)) + for (int x = 0; x < xCount * partWidth; x += (partWidth + offsetWidth)) + { + //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 diff --git a/axios/ScreenSystem/PhysicsGameScreen.cs b/axios/ScreenSystem/PhysicsGameScreen.cs index 74fc62d..3b19057 100644 --- a/axios/ScreenSystem/PhysicsGameScreen.cs +++ b/axios/ScreenSystem/PhysicsGameScreen.cs @@ -188,13 +188,12 @@ namespace GameStateManagement PlayerIndex i; if (input.IsNewButtonPress(Buttons.Back, PlayerIndex.One, out i) || input.IsNewKeyPress(Keys.Escape, PlayerIndex.One, out i)) { - if (this.ScreenState == GameStateManagement.ScreenState.Active && this.TransitionPosition == 0 && this.TransitionAlpha == 1) - { //Give the screens a chance to transition - + //if (this.ScreenState == GameStateManagement.ScreenState.Active && this.TransitionPosition == 0 && this.TransitionAlpha == 1) + //{ //Give the screens a chance to transition CleanUp(); ExitScreen(); - } + //} } base.HandleInput(gameTime, input); }