Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8492289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:40:33+00:00 2026-06-10T22:40:33+00:00

I am trying to construct an Asteroid type remake using classes, i have a

  • 0

I am trying to construct an Asteroid type remake using classes, i have a class for making the ship here:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace AsteroidsTest {
    class Character {
        KeyboardState inputKeyboard;
        Texture2D texture;
        Rectangle rectangle;
        Vector2 position;
        Vector2 origin;
        Vector2 speed;
        const float tangentialVelocity = 5f;
        public float rotation;

        public Character(Texture2D newTexture, int positionX, int positionY) {
            texture = newTexture;
            position = new Vector2(positionX, positionY);

    }
    public void Update(GameTime gametime, Keys KeyUp, Keys KeyRight, Keys KeyLeft) {
        inputKeyboard = Keyboard.GetState();
        rectangle = new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);
        position += speed;
        origin = new Vector2(rectangle.Width / 2, rectangle.Height / 2);
        if (inputKeyboard.IsKeyDown(KeyRight)) {
            rotation += 0.1f;
        } 
        else if (inputKeyboard.IsKeyDown(KeyLeft)) {
            rotation -= 0.1f;
        }
        if (inputKeyboard.IsKeyDown(KeyUp)) {
            speed.X = (float)Math.Cos(rotation) * tangentialVelocity;
            speed.Y = (float)Math.Sin(rotation) * tangentialVelocity;
        } else if (speed != Vector2.Zero) {
            speed = Vector2.Zero;
        }
    }
        public void Draw(SpriteBatch spriteBatch) {
                spriteBatch.Draw(texture, position, null, Color.White, rotation, origin, 1.0f, SpriteEffects.None, 0);
    }
}

}

But when it is drawn using my Main class below the texture on the sprite is drawn normally but when i press w to move forward, it moves me to the right. And when i rotate its as if the top of my ship is to the side, how is this possible?

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace AsteroidsTest {
    public class Asteroids : Microsoft.Xna.Framework.Game {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Character Ship;
        Texture2D playerTexture;


        public Asteroids() {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }
        protected override void Initialize() {


                base.Initialize();
        }

        protected override void LoadContent() {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            playerTexture = Content.Load<Texture2D>("Actors//Ship");
            Ship = new Character(playerTexture, 16, 16); 
        }


        protected override void UnloadContent() {

        }


        protected override void Update(GameTime gameTime) {

            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();

            Ship.Update(gameTime, Keys.Up, Keys.Right, Keys.Left);
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime) {
            GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin();
            Ship.Draw(spriteBatch);
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}

EDIT: Seems that just rotating the image 90 Degrees Clockwise fixes it, but unfortunately it defaults to that angle.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:40:34+00:00Added an answer on June 10, 2026 at 10:40 pm

    It is working as intended I suppose – by default (0 Rotation) implies object looking to the right and not up (with respect to your monitor / screen).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am trying to construct a simple update query in my model class Model_DbTable_Account extends
I'm currently trying to construct a list of bean classes in Java from a
I have been trying to construct a checkbox node tree . My specification is
Trying to construct a helper class that will return an arraylist, but I'm getting
I'm trying to construct a function of type: liftSumthing :: ((a -> m b)
I am trying to construct a serialisation system for our application that must be
I'm trying to construct a JDOQL query (using datanucleus) that will search for matches
I am presently trying to construct an OBB (Oriented Bounding Box) using the source
I'm trying to construct a linq query that pulls all nodes that have a
I am trying to construct an sql query using a while loop that increments

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.