質問

I think I do not have the Rotation and Origin parameters correct.

First off, I am programming a little Role-Playing-Game with XNA and I want to rotate a sprite depending on the direction it looks to. I have the right Rotation and everything for sure, but I think I'm probably drawing it the wrong way.

Why doesn't this work?

spriteBatch.Draw(Texture, Position, null, Color.White, Rotation, new Vector2(Texture.Width/2, Texture.Height/2), 1, SpriteEffects.None,  1);

I thought you calculate the Origin with Texture.Width / 2 and Height / 2?

役に立ちましたか?

解決

When using your origin, your position that you will see in the game will be slightly higher and to the left than without using a center origin, because you are subtracting the origin from the position when you rotate it.

Try storing your origin in a Vector2 and adding it to your position when you draw your object.

Vector2 Origin = Vector2(Texture.Width/2, Texture.Height/2);
spriteBatch.Draw(Texture, Position + Origin, null, Color.White, Rotation, Origin, 1, SpriteEffects.None,  1);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top