I am having some issues with my mouse coordinates in XNA - the 0x0 is arbitrarily near (but not in) the top left corner of my screen.
I am running the game in a windowed mode right now, but the coordinates are based off the screen, not the game window (even though the XNA documentation tells me it should be otherwise)
Thanks in advance!
Here's the code:
namespace TheGame
{
class Mousey
{
static public Vector2 pos;
static private Texture2D tex;
static public MouseState mouseState;
static public MouseState previousState;
//static public Mousey()
//{
//}
static public void Update()
{
previousState = mouseState;
mouseState = Mouse.GetState(); //Needed to find the most current mouse states.
pos.X = mouseState.X; //Change x pos to mouseX
pos.Y = mouseState.Y; //Change y pos to mouseY
}
//Drawing function to be called in the main Draw function.
static public void LoadContent(ContentManager thecontent)
{
tex = thecontent.Load<Texture2D>("mousey");
}
static public void Draw(SpriteBatch batch) //SpriteBatch to use.
{
batch.Draw(tex, pos, Color.White); //Draw it using the batch.
}
static public bool LBP()
{
if (mouseState.LeftButton == ButtonState.Pressed && previousState.LeftButton == ButtonState.Released)
{
return true;
}
else
{
return false;
}
}
}
}
In game.cs:
//sets the windows mouse handle to client bounds handle
Mouse.WindowHandle = Window.Handle;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With