Note that there are some explanatory texts on larger screens.

plurals
  1. PORotate the player in XNA
    primarykey
    data
    text
    <p>I've been looking around for a tutorial on how to do this properly and Google keeps coming up empty. Maybe this is a really simple subject, but I'm not sure what to do.</p> <p>What I've found so far gives me code that looks like this:</p> <pre><code> if (currentKeyboardState.IsKeyDown(Keys.A)) { RotationAngle += 0.01f; float circle = MathHelper.Pi * 2; RotationAngle = RotationAngle % circle; } </code></pre> <p>Only, this doesn't do much. It came from <a href="http://msdn.microsoft.com/en-gb/library/bb203869%28v=xnagamestudio.40%29.aspx" rel="nofollow">MSDN</a>. That was the best-looking solution I could find.</p> <p>All I want to do is allow the player to spin their ship around and shoot in another direction. I'm making a game that bears a fair resemblance to asteroids, but I can only shoot in one direction at the moment.</p> <p>Any help would be appreciated :)</p> <p>Edit: This is my current Player.cs:</p> <pre><code>using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace GameTest { class Player { public Texture2D PlayerTexture; public Vector2 Position; public bool Alive; public int Health; public Vector2 origin; public float RotationAngle; KeyboardState currentKeyboardState; KeyboardState previousKeyboardState; public int Width { get { return PlayerTexture.Width; } } public int Height { get { return PlayerTexture.Height; } } public void Initialize(Texture2D texture, Vector2 position) { PlayerTexture = texture; Position = position; Alive = true; Health = 10; origin.X = PlayerTexture.Width / 2; origin.Y = PlayerTexture.Height / 2; } public void Update(GameTime gameTime) { RotationAngle += 10f; previousKeyboardState = currentKeyboardState; currentKeyboardState = Keyboard.GetState(); float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; if (currentKeyboardState.IsKeyDown(Keys.A)) { //float circle = MathHelper.Pi * 2; //RotationAngle = RotationAngle % circle; } if (currentKeyboardState.IsKeyDown(Keys.D)) { //rotation } } public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(PlayerTexture, Position, null, Color.White, RotationAngle, origin, 1f, SpriteEffects.None, 0f); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload