C# Sprite Rotation

Horn

Newcomer
Joined
Mar 9, 2004
Messages
1
I'm trying to get a sprite to rotate around its center and I'm not having much luck. I've tried setting the center vector to be the center of the sprite plus its current position (so if a sprite had a center of 2 and a position of 30 its new center would be 32). I then set the sprite's tranform matrix to a rotation matrix but it acts all weird. If I leave the center alone, it rotates around 0,0 (upper left corner). Can anyone help me out?
 
Horn said:
I'm trying to get a sprite to rotate around its center and I'm not having much luck. I've tried setting the center vector to be the center of the sprite plus its current position (so if a sprite had a center of 2 and a position of 30 its new center would be 32). I then set the sprite's tranform matrix to a rotation matrix but it acts all weird. If I leave the center alone, it rotates around 0,0 (upper left corner). Can anyone help me out?

Given a 32x32 sprite, you want the center of the sprite to be the roation center which is 16x16 or "new Vector2(16f, 16f)".

The rotation is relative to the end-result, scaled, rectangle you are using from the Texture. So if you scale the rectangle from 32x32 to 16x16, with a scaling vector of Vector2(0.5f, 0.5f), then your new center would be 8x8, and you'd want to use that for your rotation center as well.
 
Last edited:
Back
Top