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 8453427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:46:18+00:00 2026-06-10T11:46:18+00:00

I am getting an error when I try to get the mouse position. This

  • 0

I am getting an error when I try to get the mouse position.

This is my player class. I am trying to make the player sprite move by mouse cursor

class Player : Actor
{
    public MouseState mState;

    EnemyManager enemyManager;

    public Player(Texture2D texture, Vector2 origin, SpriteBatch spriteBatch, EnemyManager enemyManager)
        : base(texture, origin, spriteBatch, new Vector2(250.0f, 516.0f))
    {

        this.enemyManager = enemyManager;
    }

    public override void Update(GameTime gameTime)
    {
        //KeyboardState keyboardState = Keyboard.GetState();

        //if (keyboardState.IsKeyDown(Keys.Left))
        //{
        //    if (this.Position.X > 32.0f)
        //    {
        //        this.Position -= 10.0f * Vector2.UnitX;
        //    }
        //}

        //if (keyboardState.IsKeyDown(Keys.Right))
        //{
        //    if (this.Position.X < 748.0f)
        //    {
        //        this.Position += 10.0f * Vector2.UnitX;
        //    }
        //}

        MouseState mState = Mouse.GetState();
        this.Position = new Vector2(mState.x, mState.y);


        // Collisions... 
        foreach (Enemy e in this.enemyManager.Enemies)
        {
            if (this.BoundingRectangle.Intersects(e.BoundingRectangle))
            {
                e.OnHit();

                break;
            }
        }

        base.Update(gameTime);
    }
}

and this is my Actor class which has position variables

namespace Shmup
{
    public class Actor
    {
       public Texture2D texture;
       public Vector2 origin;
       public SpriteBatch spriteBatch;
       public Vector2 position;
       public Rectangle boundingRectangle;

        public Vector2 Position
        {
             get { return position; }
             set { position = value; }
        }


        public Rectangle BoundingRectangle
        {
            get { return boundingRectangle; }
        }

        public Actor(Texture2D texture, Vector2 origin, SpriteBatch spriteBatch, Vector2 initialPosition)
        {
            this.texture = texture;
            this.origin = origin;
            this.spriteBatch = spriteBatch;
            this.position = initialPosition;

            boundingRectangle = new Rectangle((Int32)(initialPosition.X - origin.X), (Int32)(initialPosition.Y - origin.Y), texture.Width, texture.Height);
        }

        public virtual void Update(GameTime gameTime)
        {

        }

        public virtual void Draw(GameTime gameTime)
        {
            this.spriteBatch.Draw(texture, position - origin, Color.White);
        }
    }
}

my main class

public class MyGame : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    Player player;
    EnemyManager enemyManager;
    Actor actor;


    public MyGame()
    {
        graphics = new GraphicsDeviceManager(this);



        IsMouseVisible = true;

        Content.RootDirectory = "Content";
    }

    protected override void Initialize()
    {
        // TODO: Add your initialization logic here
        Actor actor = new Actor();
        base.Initialize();
    }

    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);

        startTheGame(); 
    }

    protected override void UnloadContent()
    {
        // TODO: Unload any non ContentManager content here
    }

    protected override void Update(GameTime gameTime)
    {
        // Allows the game to exit
        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
        {
            this.Exit();
        }

        this.player.Update(gameTime);
        this.enemyManager.Update(gameTime);



        base.Update(gameTime);
    }

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.Maroon);

        this.spriteBatch.Begin();


        this.player.Draw(gameTime);
        this.enemyManager.Draw(gameTime);

        this.spriteBatch.End(); 

        base.Draw(gameTime);
    }

    void startTheGame()
    {
        enemyManager = new EnemyManager(this.Content.Load<Texture2D>("Enemy"), new Vector2(16), this.spriteBatch);

        player = new Player(this.Content.Load<Texture2D>("Player"),actor.position, this.spriteBatch, enemyManager);

        enemyManager.StartTheGame(10);
    }
}
  • 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-10T11:46:20+00:00Added an answer on June 10, 2026 at 11:46 am

    This line is the problem I think:

    this.Position = new Vector2(mState.x, mState.y);
    

    x and y are not publicly exposed on MouseState. You need to capitalize them (C# is case-sensitive). Use this instead:

    this.Position = new Vector2(mState.X, mState.Y);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting this error when try to add an item to my repositories/context: Collection has
I am getting this error when I try to deploy my Web API project
I'm getting this error when I try run DB:Rake : ** Invoke db:migrate (first_time)
I keep getting this error when I try to commit a group of executed
I'm getting this error when I try to pass a task to a Celery
I'm constantly getting this error whenever I try to pass a array of Strucs
I am getting this error when I try to set a mock to have
I'm getting this error when I try and install node on my new mac
I am getting the following error: try { Element.update(status, This product doesn't exist.); }
I am getting this error when I try to read a property from a

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.