Sign in to follow this  

XNA 2D sprite rotation

This topic is 2435 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

[color="#4A4A4A"]
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;

[code][/color]
[color="#4A4A4A"]
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))
{
cameraAngle+=0.01f;

}


base.Update(gameTime);
}


protected override void Draw(GameTime gameTime)
{

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

base.Draw(gameTime);
}[/color][color=#4A4A4A][/code][/color]
[color="#4A4A4A"]

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.

so

[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
Sign in to follow this