0
votes

I just begun learning XNA 4.0 and I have a question. I created a sprite and I need to rotate it when a specific event occurs. I would also like to know how to rescale that same sprite while in the middle of the game. I tried this:

Texture2D theSprite;

  protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);

        spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);

        if (direction=="right")
        {
            spriteBatch.Draw(theSprite, spritePosition, null, Color.White, 0, new Vector2(0, 0), .7f, SpriteEffects.None, 0); 
        }

But it changes the sprite's position and I'm guessing there has to be a better way, right?

Thanks!

1

1 Answers

0
votes

It looks it change position because rotation center is at vector(0,0), you have to change this to be in the middle of object.

Origin = new Vector2(texture.Width / 2, texture.Height / 2);
Rotate = MathHelper.ToRadians(45)
Scale = 0.7f

spriteBatch.Draw(theSprite, spritePosition, null, Color.White, Rotate, Origin, Scale , SpriteEffects.None, 0);

enter image description here