PathfindingTest.Map.MiniMap.GetScaledInstanceNoRenderTargetChange C# (CSharp) Méthode

GetScaledInstanceNoRenderTargetChange() private méthode

Gets a scaled instance of a texture.
private GetScaledInstanceNoRenderTargetChange ( Microsoft.Xna.Framework.Graphics.Texture2D originalTexture, Vector2 targetSize, RenderTarget2D newRenderTarget ) : Microsoft.Xna.Framework.Graphics.Texture2D
originalTexture Microsoft.Xna.Framework.Graphics.Texture2D The original texture
targetSize Vector2 The vector target size.
newRenderTarget Microsoft.Xna.Framework.Graphics.RenderTarget2D
Résultat Microsoft.Xna.Framework.Graphics.Texture2D
        private Texture2D GetScaledInstanceNoRenderTargetChange(Texture2D originalTexture, Vector2 targetSize, RenderTarget2D newRenderTarget)
        {
            // Clear the scene
            Game1.GetInstance().GraphicsDevice.Clear(Color.Transparent);

            // Create the new SpriteBatch that will be used to scale the Texture
            SpriteBatch cSpriteBatch = new SpriteBatch(Game1.GetInstance().GraphicsDevice);

            // Draw the scaled Texture
            cSpriteBatch.Begin();
            cSpriteBatch.Draw(originalTexture, new Rectangle(0, 0, (int)targetSize.X, (int)targetSize.Y), Color.White);
            cSpriteBatch.End();

            Texture2D result = new Texture2D(Game1.GetInstance().GraphicsDevice, (int)targetSize.X, (int)targetSize.Y);
            int[] data = new int[(int)targetSize.X * (int)targetSize.Y];
            Game1.GetInstance().GraphicsDevice.SetRenderTarget(null);
            newRenderTarget.GetData(data);
            Game1.GetInstance().GraphicsDevice.SetRenderTarget(newRenderTarget);
            result.SetData(data);
            // Set the Texture To Return to the scaled Texture
            return result;
        }