Skip to main content
gamedev.net
🔒 Locked

C# Sprite problems

Started by Horn 1 reply 650+ views
Original Post
Horn
Horn
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?
Pinzmon
Pinzmon
After you rotate it, you need to translate it back to its center. Here''s a snip from my sprite drawing routine:

D3DSprite.Transform = Matrix.Scaling(scale,scale,1.0f) * Matrix.RotationZ(rotationAngle) * Matrix.Translation(center);

D3DSprite.Draw(spriteDef.SpritePage.SpritePageTexture, spriteDef.SourceRectangle, center, position, Color.White.ToArgb());
Horn
Horn
Thanks that seems to have solved my problem.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.