Sign in to follow this  

XNA 2D sprite rotation

Recommended Posts

What I'm trying to do is make a CCTV camera rotate about a point by itself. I've looked about and can't seem to find anything. I've found lots on making objects rotate around other objects, but nothing on making one sprite rotate on the spot.

I thought it would be a simple case of updating the angle the spritesits at, but nothing happens when I press my keys.

Not this is going to be an enemy object, not the games camera. Making a 2D stealth/spy game.
The code I've is like this;

Texture2D camera;

Vector2 cameraOrigin = new Vector2(11, 50);
float cameraAngle = 10.0f;
Vector2 cameraPosistion = new Vector2(400, 200);

protected override void Update(GameTime gameTime)

if (keyboardstate.IsKeyDown(Keys.A))



protected override void Draw(GameTime gameTime)

new Rectangle(100, 200, camera.Width, camera.Height), null, Color.White, cameraAngle, cameraOrigin, SpriteEffects.None, 1);


Can anyone see what I'm doing wrong or missing?[/color]

Share this post

Link to post
Share on other sites
cameraAngle should be a Vector2, which is the coordinates within the texture2d that you want to rotate your sprite.


[code]Vector2 cameraAngle = new Vector2(0f, 0f);[/code]

would make the sprite rotate around the top left corner where as :-

[code]Vector2 cameraAngle = new Vector2(camera.Width, camera.Height);[/code]

would be bottom right and

[code]Vector2 cameraAngle = new Vector2(camera.Width / 2, camera.Height / 2);[/code]

would be the centre;

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this