Esempio n. 1
0
 internal bool LoadTexture(string name, string path)
 {
     if (!Textures.ContainsKey(name))
     {
         QTexture t = new QTexture(this, Load <Texture2D>(path));
         Textures.Add(name, t);
         return(true);
     }
     return(false);
 }
        /// <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");
            }
        }
Esempio n. 3
0
 internal QContentManager(Game engine)
 {
     MonoGraphicsDevice = engine.GraphicsDevice;
     MonoContentManager = engine.Content;
     Atlases            = new List <QTextureAtlas>();
     Textures           = new Dictionary <string, QTexture>();
     Fonts  = new Dictionary <string, QFont>();
     Sounds = new Dictionary <string, QSound>();
     Music  = new Dictionary <string, QMusic>();
     //setting up the unknown texture once
     if (UnknownTexture == null)
     {
         var texture = new Texture2D(MonoGraphicsDevice, 2, 2);
         var c       = new QColor[]
         {
             QColor.White, QColor.Purple, QColor.White, QColor.Purple
         };
         texture.SetData(c);
         UnknownTexture = new QTexture(this, texture);
     }
 }
Esempio n. 4
0
//		/// <summary>
//		/// Draws filled in circle
//		/// </summary>
//		/// <param name="t"></param>
//		/// <param name="radius"></param>
//		/// <param name="c"></param>
//		public void DrawCircle(QTransform t, float radius, QColor c)
//		{
//			sb.DrawCircle(t.Position, radius, 20, c, radius);
//		}
//
//		/// <summary>
//		/// Assumes that the rectangle origin is in the middle
//		/// </summary>
//		/// <param name="t"></param>
//		/// <param name="width"></param>
//		/// <param name="height"></param>
//		/// <param name="color"></param>
//		public void DrawRect(QTransform t, float width, float height, QColor color)
//		{
//			var v = t.Position;
//			//sb.DrawRectangle(v - new QVec(width, height)/2f, new QVec(width, height), color);
//			sb.FillRectangle(v - new QVec(width, height)/2f, new QVec(width, height), color);
//			//sb.FillRectangle(t.Position.X, t.Position.Y, width, height, color, t.Rotation);
//		}

        internal virtual void Draw(QTexture t, QVector2 pos, QColor c)
        {
            sb.Draw(t, pos, c);
        }