tags:

views:

30

answers:

2

Ok, I have this ship object which the user controls using the arrow keys.

        if (aCurrentKeyboardState.IsKeyDown(Keys.Left) == true)
            mAngle -= 0.1f;
        else if (aCurrentKeyboardState.IsKeyDown(Keys.Right) == true)
            mAngle += 0.1f;

        if (aCurrentKeyboardState.IsKeyDown(Keys.Up) == true)
        {
           // mSpeed.Y = SHIP_SPEED;
           // mDirection.Y = MOVE_UP;

            velocity.X = (float)Math.Cos(mAngle) * SHIP_SPEED;
            velocity.Y = (float)Math.Sin(mAngle) * SHIP_SPEED;
        }
        else if (aCurrentKeyboardState.IsKeyDown(Keys.Down) == true)
        {
            mSpeed.Y = SHIP_SPEED;
            mDirection.Y = MOVE_DOWN;
        }

The following 2 methods are in another class.

//Update the Sprite and change it's position based on the passed in speed, direction and elapsed time.
    public void Update(GameTime theGameTime, Vector2 velocity, float theAngle)
    {
        Position += velocity * (float)theGameTime.ElapsedGameTime.TotalSeconds;
        shipRotation = theAngle;
    }

    //Draw the sprite to the screen
    public void Draw(SpriteBatch theSpriteBatch)
    {
        Vector2 Origin = new Vector2(mSpriteTexture.Width / 2, mSpriteTexture.Height / 2);

        theSpriteBatch.Draw(mSpriteTexture, Position, new Rectangle(0, 0, mSpriteTexture.Width, mSpriteTexture.Height), 
            Color.White, shipRotation, Origin, Scale, SpriteEffects.None, 0);
    }

The problem is that: the program thinks the front of the ship is one of the side wings, so in a way it's going sideways when I press up. I don't know why this is.

Suggestions?

A: 

If I understand your problem correctly, you could solve your problem just by rotating your ship texture. Just try adding 90 or -10 to your shipRotation in the Draw Method:

theSpriteBatch.Draw(mSpriteTexture, Position, new Rectangle(0, 0, mSpriteTexture.Width, mSpriteTexture.Height), 
        Color.White, shipRotation + 90, Origin, Scale, SpriteEffects.None, 0);

or

theSpriteBatch.Draw(mSpriteTexture, Position, new Rectangle(0, 0, mSpriteTexture.Width, mSpriteTexture.Height), 
        Color.White, shipRotation - 90, Origin, Scale, SpriteEffects.None, 0);

Hope that helps!

Björn
I did that but it looks as if it's less than 90. I think it might be that by rotations are not measured in radians... I don't want a workaround to my problem because it's going to affect all other derived classes.
mike
A: 

Then change your original sprite to match what your program "thinks" is the front of the ship.

David Yenglin