Iâve been working with Monogame the past three years, and it is great. But Iâve had some difficult with mouse position. It used to work, but if I use classes, it doesnât work. This is my test project: Game1 class:
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Playerclass Player;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
this.IsMouseVisible = true;
base.Initialize();
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
Player = new Playerclass();
Player.LoadContent(Content);
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
Player.Update(gameTime);
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
//spriteBatch.Draw(Guy, Mouse.GetState().Position.ToVector2(), Color.White);
Player.Draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
Player class:
Texture2D Guy;
Point Position;
public void LoadContent(ContentManager Content)
{
Guy = Content.Load<Texture2D>("Guy");
}
public void Update(GameTime gameTime)
{
Position = Mouse.GetState().Position;
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(Guy, Position.ToVector2(), Color.White);
}
It just returns 0,0! What is the problem? Please help!
Mouse position just returns 0,0. And leftbutton is always false. I donât know if it is just with my computer, if so, I donât know the problem. I have installed monogame over and over again, but It still doesnât work. It has been happening for one year.
OMG! Thank you so, so much! Thank you! I used to inherit Game1 because of some public variables! Do you know another way to share public variables? Anyway, thank you so, so much! You are a lifesaver!