When do you get Mouse.getstate().X or Y as negative?

Started by
1 comment, last by rip-off 10 years, 7 months ago

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;
}

And:

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 value a l as negative even though the debug is initiate after a click on theGameWindow screen. Sometimes it works fine sometime does not. I dont know why does it give me negative value. And when I used them with my Rectangle i get Rectangle.X and Rectangle.Y as0.

Advertisement

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.mouse.windowhandle.aspx

This pretty much covers it. You want to figure out where your (0,0) origin is.

Please use [[size="1"]code] and [[size="1"]/code] tags, or the "code" tool in the WYSIWYG editor when pasting source code.

This topic is closed to new replies.

Advertisement