/// <summary> /// Draws the given sprite within its own SpriteBatch.Begin/End block. /// </summary> /// <param name="sprite"></param> private void DrawSpriteBorder(BorderSprite sprite) { spriteBatch.Begin(); DrawSpriteBorderThin(sprite); spriteBatch.End(); }
/// <summary> /// Draws a Sprite primitive without starting a new SpriteBatch draw operation. /// </summary> /// <param name="sprite"></param> private void DrawSpriteBorderThin(BorderSprite sprite) { DividedRectangleSizes source = new DividedRectangleSizes(sprite.Resource.Width, sprite.Resource.Height, sprite.Border); DividedRectangleSizes destination = new DividedRectangleSizes(sprite.Size.X, sprite.Size.Y, sprite.Border); Rectangle[] sourceRectangles = source.GenerateRectangles(); Rectangle[] destinationRectangles = destination.GenerateRectangles(); for (int index = 0; index < destinationRectangles.Length; index++) { destinationRectangles[index].Offset((int)sprite.Position.X, (int)sprite.Position.Y); } for (int index = 0; index < sourceRectangles.Length; index++) { Color color = sprite.TintColor.ToXNAColor(); color.A = (byte)(color.A * sprite.Opacity); spriteBatch.Draw( sprite.Resource, destinationRectangles[index], sourceRectangles[index], color); } }