/// <summary> /// Renders all thge objects, and debug information /// </summary> /// <param name="renderer"></param> internal void OnDraw(QSpriteRenderer renderer) { renderer.Begin(); Entities.SpriteObjects.For(s => s.OnDrawSprite(renderer)); renderer.End(); //normally ends here, debug renders here, laggy af if (Debug.DebugLevel < 2) { return; } var c = Camera.Bounds; Matrix a = Matrix.CreateOrthographicOffCenter(c.Left.ToSim(), c.Right.ToSim(), c.Bottom.ToSim(), c.Top.ToSim(), 0, 1); DebugView.RenderDebugData(ref a); }
/// <summary> /// Takes the created target and draws to it using the space that it needed for all textures /// </summary> /// <param name="target"></param> /// <param name="biggetsHeight"></param> /// <param name="maxWidth"></param> void RenderAtlas(RenderTarget2D target, int biggetsHeight, int maxWidth) { //slows down code but useful for debugging const bool takePictureOfAtlas = false; target.GraphicsDevice.SetRenderTargets(target); var render = new QSpriteRenderer(Engine); Rectangles = new Dictionary <string, QRectangle>(); var pos = QVector2.Zero; render.ClearColor = QColor.Transparent; render.Begin(); //var textures = ContentManager.Textures.ToList(); var textures = Textures; int texturesOnThisSheet = 0; for (int i = 0; i < textures.Count; i++) { var t = textures[i]; if (pos.X + t.Width > maxWidth) { pos.Y += biggetsHeight; pos.X = 0; } render.Draw(t, pos, QColor.White); Rectangles.Add(t.Name.Split('/').Last(), new QRectangle(pos, t.Bounds.Size)); pos.X += t.Width + 1; } render.End(); render.gd.SetRenderTarget(null); if (Texture != null) { ((Texture2D)Texture).Dispose(); } Texture = new QTexture(ContentManager, target); if (takePictureOfAtlas) { Texture.SaveAsPng($"{DateTime.Now.Minute}-{DateTime.Now.Second}.png"); } }