Skip to content

Commit

Permalink
move and unwind origin scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
nkast committed Feb 10, 2017
1 parent d9750e7 commit d7689dc
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions MonoGame.Framework/Graphics/SpriteBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,9 @@ public void Draw (Texture2D texture,
float layerDepth)
{
CheckValid(texture);

origin.X = origin.X * ((float)destinationRectangle.Width / (float)( (sourceRectangle.HasValue && sourceRectangle.GetValueOrDefault().Width != 0) ? sourceRectangle.GetValueOrDefault().Width : texture.Width));
origin.Y = origin.Y * ((float)destinationRectangle.Height) / (float)( (sourceRectangle.HasValue && sourceRectangle.GetValueOrDefault().Height != 0) ? sourceRectangle.GetValueOrDefault().Height : texture.Height);

var item = _batcher.CreateBatchItem();
item.Texture = texture;

var item = _batcher.CreateBatchItem();
item.Texture = texture;

// set SortKey based on SpriteSortMode.
switch ( _sortMode )
Expand All @@ -420,11 +417,23 @@ public void Draw (Texture2D texture,
_texCoordTL.Y = srcRect.Y / (float)texture.Height;
_texCoordBR.X = (srcRect.X + srcRect.Width) / (float)texture.Width;
_texCoordBR.Y = (srcRect.Y + srcRect.Height) / (float)texture.Height;

if(srcRect.Width != 0)
origin.X = origin.X * (float)destinationRectangle.Width / (float)srcRect.Width;
else
origin.X = origin.X * (float)destinationRectangle.Width / (float)texture.Width;
if(srcRect.Height != 0)
origin.Y = origin.Y * (float)destinationRectangle.Height / (float)srcRect.Height;
else
origin.Y = origin.Y * (float)destinationRectangle.Height / (float)texture.Height;
}
else
{
_texCoordTL = Vector2.Zero;
_texCoordBR = Vector2.One;

origin.X = origin.X * (float)destinationRectangle.Width / (float)texture.Width;
origin.Y = origin.Y * (float)destinationRectangle.Height / (float)texture.Height;
}

if ((effects & SpriteEffects.FlipVertically) != 0)
Expand Down

0 comments on commit d7689dc

Please sign in to comment.