Beispiel #1
0
        /// <summary>
        /// Draws the sub sprite with the given index from the atlas using the nine cut method
        /// This is mostly useful for gui elements like forms and buttons
        /// </summary>
        /// <param name="sb"></param>
        /// <param name="index"></param>
        /// <param name="dest"></param>
        /// <param name="source"></param>
        /// <param name="color"></param>
        /// <param name="destEdge"></param>
        /// <param name="sourceEdge"></param>
        public void DrawNineCut(SpriteBatch sb, string spriteDef, Rectangle dest, Rectangle?source = null, Color?color = null, int?destEdge = null, int?sourceEdge = null, Vector2?scale = null, Vector2?origin = null, float rotation = 0)
        {
            Rectangle def;
            bool      res = SpriteDefinitions.TryGetValue(spriteDef, out def);

            if (!res)
            {
                ConsoleManager.Instance.WriteLine($"Could not find sprite '{spriteDef}' in '{BaseTexture.Path}'");
                return;
            }

            if (source == null)
            {
                source = def;
            }

            Rectangle finalSource = new Rectangle(def.X + source.Value.X, def.Y + source.Value.Y, source.Value.Width, source.Value.Height);

            BaseTexture.DrawNineCut(sb, dest, finalSource, color, destEdge, sourceEdge, scale, origin, rotation);
        }