public void AddColor(Texture2D texture, Rectangle sourceRectangle, Rectangle rectangle, Color color) { _textureUpdating = true; var renderTarget = new RenderTarget2D(GraphicManager.Instance.GraphicsDevice, Settings.ScreenWidth, Settings.ScreenHeight); GraphicManager.Instance.GraphicsDevice.SetRenderTarget(renderTarget); GraphicManager.Instance.GraphicsDevice.Clear(Color.Black); _spritebatch.Begin(); _spritebatch.Draw(_renderTarget, Vector2.Zero, Color.White); _spritebatch.Draw(texture, rectangle, sourceRectangle, color, (float)_random.NextDouble(), new Vector2(0.5f, 0.5f), SpriteEffects.None, 0); _spritebatch.End(); GraphicManager.Instance.GraphicsDevice.SetRenderTarget(null); //_textureGame = (Texture2D)renderTarget; _renderTarget.Dispose(); _renderTarget = renderTarget; //_renderTarget.Dispose(); //spritebatch.Dispose(); _textureUpdating = false; }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); _spriteBatch.Begin(); _stopwatch.Restart(); World.Draw(gameTime.ElapsedGameTime.TotalMilliseconds, _spriteBatch); _spriteBatch.DrawString(Utils.FontManager.Instance.GetFont(FontEnum.ARIAL_16), "Draw : " + _stopwatch.Elapsed.TotalMilliseconds.ToString("0.000") + " ms", new Vector2(10, 10), Color.Yellow); _spriteBatch.DrawString(Utils.FontManager.Instance.GetFont(FontEnum.ARIAL_16), "Update : " + _updateTime.ToString("0.000") + " ms", new Vector2(10, 30), Color.Yellow); _spriteBatch.DrawString(Utils.FontManager.Instance.GetFont(FontEnum.ARIAL_16), "Fps : " + (10000 / ((_updateTime + _stopwatch.Elapsed.TotalMilliseconds) * 10)).ToString("00.00"), new Vector2(10, 50), Color.Yellow); _spriteBatch.DrawString(Utils.FontManager.Instance.GetFont(FontEnum.ARIAL_16), "Draw calls : " + _spriteBatch.DrawCallsCount, new Vector2(10, 70), Color.Yellow); _spriteBatch.End(); //_basicUI.Draw(gameTime.ElapsedGameTime.TotalMilliseconds); base.Draw(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); _spriteBatch.Begin(); _stopwatch.Restart(); SpriteFont font = FontManager.Instance.GetFont("Arial-10"); _gameManager.Draw(gameTime, _spriteBatch); _drawTime = _stopwatch.ElapsedMilliseconds; _spriteBatch.DrawString(font, "Update : " + _updateTime.ToString("0.000") + " ms", new Vector2(10, 10), Color.Yellow); _spriteBatch.DrawString(font, "Draw : " + _drawTime.ToString("0.000") + " ms", new Vector2(10, 30), Color.Yellow); if (_minFrameCounter != int.MaxValue) { _spriteBatch.DrawString(font, "Fps : " + _lastFrameCounter.ToString("00.00") + ", Min : " + _minFrameCounter.ToString("00.00") + ", Max : " + _maxFrameCounter.ToString("00.00"), new Vector2(10, 50), Color.Yellow); } else { _spriteBatch.DrawString(font, "Fps : " + _lastFrameCounter.ToString("00.00") + ", Max : " + _maxFrameCounter.ToString("00.00"), new Vector2(10, 50), Color.Yellow); } _spriteBatch.DrawString(font, "DrawCallCount : " + _spriteBatch.DrawCallsCount, new Vector2(10, 70), Color.Yellow); _spriteBatch.End(); base.Draw(gameTime); }
public void UpdateTexture() { _textureUpdating = true; MySpriteBatch spritebatch = new MySpriteBatch(GraphicManager.Instance.GraphicsDevice); Width = Settings.SubZoneWidth * (int)Settings.Tile_Size; Height = Settings.SubZoneHeight * (int)Settings.Tile_Size; var renderTarget = new RenderTarget2D(GraphicManager.Instance.GraphicsDevice, Width, Height); GraphicManager.Instance.GraphicsDevice.SetRenderTarget(renderTarget); GraphicManager.Instance.GraphicsDevice.Clear(Color.Transparent); Sprite spriteGrass = SpriteManager.Instance.GetSprite("Grass"); Sprite spriteRock = SpriteManager.Instance.GetSprite("Rock"); Sprite spriteDirt = SpriteManager.Instance.GetSprite("Dirt"); Sprite spriteWater1 = SpriteManager.Instance.GetSprite("Water1"); Sprite spriteWater2 = SpriteManager.Instance.GetSprite("Water2"); Sprite spriteWater3 = SpriteManager.Instance.GetSprite("Water3"); spritebatch.Begin(); for (var line = _zone.Height - 1; line >= 0; line--) { for (var col = _zone.Width - 1; col >= 0; col--) { var tile = _zone.LayerFloor.Tiles[line, col]; var position = Convert2DToIso(new Vector3(col, line, tile.Altitude)); position.X += renderTarget.Width * 0.5f - Settings.Tile_Size * 0.5f; position.Y += renderTarget.Height * 0.5f - Settings.Tile_Size * 0.5f; if (tile.Terrain.Type == TypeTerrain.Rock) { spritebatch.Draw(spriteRock.Texture, new Rectangle((int)position.X, (int)position.Y, (int)Settings.Tile_Size, (int)Settings.Tile_Size), spriteRock.RectangleSource, spriteRock.Color); } else if (tile.Terrain.Type == TypeTerrain.Grass) { spritebatch.Draw(spriteGrass.Texture, new Rectangle((int)position.X, (int)position.Y, (int)Settings.Tile_Size, (int)Settings.Tile_Size), spriteGrass.RectangleSource, spriteGrass.Color); } else if (tile.Terrain.Type == TypeTerrain.Dirt) { spritebatch.Draw(spriteDirt.Texture, new Rectangle((int)position.X, (int)position.Y, (int)Settings.Tile_Size, (int)Settings.Tile_Size), spriteDirt.RectangleSource, spriteDirt.Color); } } } spritebatch.End(); GraphicManager.Instance.GraphicsDevice.SetRenderTarget(null); _texture = (Texture2D)renderTarget; _textureUpdating = false; }