public void Draw(Texture2D texture, Vector2 position, Nullable <Rectangle> sourceRectangle, Color color, float rotation,
Vector2 origin, Vector2 scale, SpriteEffects effect, float depth)
{
if (texture == null)
{
throw new ArgumentException("texture");
}
SpriteBatchItem item = _batcher.CreateBatchItem();
item.Depth = depth;
item.TextureID = (int)texture.ID;
Rectangle rect;
if (sourceRectangle.HasValue)
{
rect = sourceRectangle.Value;
}
else
{
rect = new Rectangle(0, 0, texture.Image.ImageWidth, texture.Image.ImageHeight);
}
Vector2 texCoordTL = texture.Image.GetTextureCoord(rect.X, rect.Y);
Vector2 texCoordBR = texture.Image.GetTextureCoord(rect.X + rect.Width, rect.Y + rect.Height);
if ((effect & SpriteEffects.FlipVertically) != 0)
{
float temp = texCoordBR.Y;
texCoordBR.Y = texCoordTL.Y;
texCoordTL.Y = temp;
}
if ((effect & SpriteEffects.FlipHorizontally) != 0)
{
float temp = texCoordBR.X;
texCoordBR.X = texCoordTL.X;
texCoordTL.X = temp;
}
item.Set
(
position.X,
position.Y,
-origin.X * scale.X,
-origin.Y * scale.Y,
rect.Width * scale.X,
rect.Height * scale.Y,
(float)Math.Sin(rotation),
(float)Math.Cos(rotation),
color,
texCoordTL,
texCoordBR
);
}