# Xna Sprite Rotation Problem

## Recommended Posts

This may not be a problem just how the rotation works but unsure so i came here to ask. Well i got this texture and when i rotate it by making origin the center of the image it rotates fine but when i use the origin of 0,0 as the vector to rotat it on the texture rotates in a small circle around the point. Well I want to rotate the texture right on a pinpoint without it moving off in an orbit around the point. Is that possible? Thanks, Much appreciated, Anthony out

##### Share on other sites
You did basically answer you own question. The origin sets the point the sprite will rotate around. If you leave it at the default the sprite will rotate around the 0,0 point, if you set it to the centre then it will rotate around the centre... That's just the way it works.

##### Share on other sites
sigh, maybe it should be called orbit then lol is there a way to turn a sprite at a point? without it orbiting around the point the point?

Anthony out
Thanks for the quick responce Dark

##### Share on other sites
What exactly are you trying to do...? Do you want the sprite to rotate without actually "tilting around"?

##### Share on other sites
Maybe he is trying to translate the sprite to a different point and rotate around that? But then he could just change the position, and rotate around the origin...

##### Share on other sites
All I want to do is turn a texture at a point and when it turns its a different angle of course but its still fixed at a point. I dont want the image to orbit around a point, I want the image to turn at a point. AT being the operative word.

Let me make an example. hmmm now what kind of example can I make...lets say theres a crank to turn a gear. Well the crank turns but doesnt leave its central point. If the crank orbited the point it would be in the wrong positions and look weird LOl.

Anthony out
Thanks for the replies.

##### Share on other sites
Quote:
 Original post by writtensoulsAll I want to do is turn a texture at a point and when it turns its a different angle of course but its still fixed at a point. I dont want the image to orbit around a point, I want the image to turn at a point. AT being the operative word.

So rotate around the center of the texture. Normally, the process here is to translate your object to the origin, perform the rotation, and translate back.

##### Share on other sites
Maybe i should just give up lol no one seems to get what im saying. Well Rotate is not the function i need obviously. Now that i understand what it does it just isnt going to work. I never thought it would be this difficult. with a circle rotating at the center it doesnt move from its spot and it spins, Yay. lol and if you rotate a line from the center it will look like a helicoper yay lol. ok my problem comes in when you dont want that to happen.

say you have a arm connected to a joint. Well the arm turns at the joint. The arm is connected to the joint. it moves but stays connected to the joint. Now a Arm doesnt orbit around the joint Lol when we move our arm it doesnt leave the joint in orbit lol. thats just wrong, not right, evil. well that is my problem. I want the point to be as a joint that it turns at. I dont want the arm to orbit around the joint like some demented planet LOL

Anthony out

##### Share on other sites
Quote:
 Original post by writtensoulssay you have a arm connected to a joint. Well the arm turns at the joint. The arm is connected to the joint. it moves but stays connected to the joint. Now a Arm doesnt orbit around the joint Lol when we move our arm it doesnt leave the joint in orbit lol. thats just wrong, not right, evil. well that is my problem. I want the point to be as a joint that it turns at. I dont want the arm to orbit around the joint like some demented planet LOL

Right, so translate your object such that the pivot point is at the origin, perform the rotation, and translate back...

##### Share on other sites
so basically do the rotation outside of the spritebatch.draw function. So rotate it outside of draw then draw it at the point I want? Isnt that somewhat slow? Well thanks I think that helps a lot if i understand right.

Anthony out

##### Share on other sites
Yes, what Driv3MeFar said. For example:

Matrix transformation = Matrix.CreateTranslation(new Vector3(distanceToOrigin.X, distanceToOrigin.Y, distanceToOrigin.Z)) * Matrix.CreateRotationZ(rotationAmount) * Matrix.CreateTranslation(new Vector3(-distanceToOrigin.X, -distanceToOrigin.Y, -distanceToOrigin.Z));

Then just translate your points with the transformation matrix.

##### Share on other sites
ok thanks for all the help everyone. I'm new to programming and I dont know about matrices yet so i guess ill have to learn about them before I can do what i wanted. Math sucks lol. You use matricies for 2d stuff too? oh wells. thanks now i know what i was doing wrong. :D

Anthony out

##### Share on other sites
I think I know what you mean:

Texture2D image;
Vector2 origin;

origin = new Vector2(image.width/2, image.height/2);

Now in draw you do something like this:

batch.Draw(tex, Position, null, Color.White, angle, origin, 1.0f, SpriteEffects.None, 1.0f);

Just make sure that your origin is the center of the image like people before have said.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627716
• Total Posts
2978783

• 9
• 21
• 14
• 12
• 42