public void CreateMiniMap(Boolean dummy)
{
int targetWidth = (int)(this.map.mapTiles.GetLength(0) * (int)this.miniMapTileSize.X);
int targetHeight = (int)(this.map.mapTiles.GetLength(1) * (int)this.miniMapTileSize.Y);
RenderTargetBinding[] OldRenderTargetBindings = Game1.GetInstance().GraphicsDevice.GetRenderTargets();
Game1.GetInstance().GraphicsDevice.SetRenderTargets(null);
// Get the Texture with the screen drawn on it
// Create the Render Target to draw the scaled Texture to
RenderTarget2D newRenderTarget =
new RenderTarget2D(Game1.GetInstance().GraphicsDevice, targetWidth, targetHeight);
// Set the given Graphics Device to draw to the new Render Target
Game1.GetInstance().GraphicsDevice.SetRenderTarget(newRenderTarget);
// Clear the scene
Game1.GetInstance().GraphicsDevice.Clear(Color.Transparent);
// Create the new SpriteBatch that will be used to scale the Texture
SpriteBatch sb = new SpriteBatch(Game1.GetInstance().GraphicsDevice);
// Draw the scaled Texture
sb.Begin();
for (int i = 0; i < this.map.mapTiles.GetLength(0); i++)
{
for (int j = 0; j < this.map.mapTiles.GetLength(1); j++)
{
sb.Draw(this.map.mapTiles[i, j],
new Rectangle(i * (int)this.miniMapTileSize.X, j * (int)this.miniMapTileSize.Y,
(int)this.miniMapTileSize.X, (int)this.miniMapTileSize.Y),
Color.White);
}
}
// End it
sb.End();
// Clear Graphics Device render target
Game1.GetInstance().GraphicsDevice.SetRenderTarget(null);
// Restore the given Graphics Device's Render Target Bindings
Game1.GetInstance().GraphicsDevice.SetRenderTargets(OldRenderTargetBindings);
this.miniMapTexture = new Texture2D(Game1.GetInstance().GraphicsDevice, targetWidth, targetHeight);
int[] data = new int[targetWidth * targetHeight];
newRenderTarget.GetData(data);
this.miniMapTexture.SetData(data);
// Set the Texture To Return to the scaled Texture
}