I am currently having an issue with Monogame while drawing with a SourceRectangle and Origin. When the Origin is (0,0) everything works as expected other than, well, Rotation. When the SourceRectangle is the whole image it works as expected with correct origin. With both variables the way they should be, this happens as the Sourcerectangle “zooms” in(by subtracting width and height, so basically animation): http://gyazo.com/7fed3d2e228beb15c644d43155d226db .
To recreate the problem yourself, use the following code with a 64x64 image.
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace Playground {
public class Game1 : Game {
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D _image;
float _angle = 0f;
Rectangle old;
Vector2 center;
public Game1() {
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize() {
base.Initialize();
old = new Rectangle(0, 0, _image.Width, _image.Height);
center = new Vector2((float)_image.Width / 2, (float)_image.Height / 2);
this.IsMouseVisible = true;
}
protected override void LoadContent() {
spriteBatch = new SpriteBatch(GraphicsDevice);
_image = Content.Load<Texture2D>("Collider");
}
protected override void UnloadContent() {
}
protected override void Update(GameTime gameTime) {
_angle += 0.1f;
if(Keyboard.GetState().IsKeyDown(Keys.W))
old = new Rectangle(old.X, old.Y, old.Width - 1, old.Height - 1);
if(Keyboard.GetState().IsKeyDown(Keys.S))
old = new Rectangle(old.X, old.Y, old.Width + 1, old.Height + 1);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime) {
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(_image, new Rectangle(Mouse.GetState().Position.X, Mouse.GetState().Position.Y, 64, 64), old, Color.White, _angle, center, SpriteEffects.None, 0f);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
Help greatly appreciated!