Jump to content
• Advertisement

Public Group

# XNA Sprite Rotation question

This topic is 4232 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

I am attempting my first game of any type, using XNA. Basically trying to do an Atari type Tank game. I have managed to setup full screen, add a tank sprite, and implement keyboard movement. Trying to keep it simple one step at a time. My next challenge was to implement rotation. I have managed to get the tank to rotate in circles, clockwise and counter-clockwise. Again keeping it simple, I am using the standard WASD keys for movement. W moves the tank forward, S moves it backward. Now here is my problem, how do I adjust movement based on the rotation of the tank?? The tank starts facing straight down, and so far I can move it up and down the Y axis, the rotation allows for turning, but, not sure how to calculate X and Y values based on direction. Any help would be appreciated. Thanks, Shawn

#### Share this post

##### Share on other sites
Advertisement
Here's the update method I used for an old game I wrote a while back with a similar control scheme to that:

private const double mathpioneeighty = Math.PI / 180;public void Update(float delta)		{			if (mVelocity > 0f)			{				double radian = (double)mDirection * mathpioneeighty;				float scale = mVelocity * delta;				x += (float)Math.Cos(radian)* scale;				y += (float)Math.Sin(radian)* scale;			}		}

In this code, I'm storing the direction as an angle in degrees (mDirection), and the velocity (mVelocity) as a scalar value.

#### Share this post

##### Share on other sites
Thanks joel, I think I follow that and appears to be exactly what I wanted, appreciate it.

Shawn

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5
• Advertisement

• 14
• 39
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631717
• Total Posts
3001877
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!