I am creating a game in which I use a function:
int x()
{
int px = 100;
int pxend = 128;
int xx = 0;
for (int i = 0; i < 6; i++)
{
l = Mouse.GetState().X;
if (l > px && l < pxend)
{
xx = px;
break;
}
else
{
px += 128;
pxend += 128;
}
}
return xx;
}
int y()
{
int px = 100;
int pxend = 128;
int xx = 0;
for (int i = 0; i < 4; i++)
{
l = Mouse.GetState().X;
if (l > px && l < pxend)
{
xx = px;
break;
}
else
{
px += 128;
pxend += 128;
}
}
return xx;
}
But when I debug I get a l
value as negative even though the debug is initiate after a click on the GameWindow
screen. Sometimes it works fine, sometimes does not. I don't know why it gives me negative value. And when I use them with my Rectangle
I get Rectangle.X
and Rectangle.Y
as 0.