C# Sprite Rotation

Horn

New member
Joined
Mar 9, 2004
Messages
1
Im trying to get a sprite to rotate around its center and Im not having much luck. Ive 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 sprites 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:
Im trying to get a sprite to rotate around its center and Im not having much luck. Ive 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 sprites 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 youd want to use that for your rotation center as well.
 
Last edited by a moderator:
Back
Top