1
\$\begingroup\$

I'm making a menu in XNA; and to solve clunky input via arrow keys, I thought I would use mouse input. I got everything to work perfectly, then I tried to click on something specific and nothing happened. To troubleshoot, I drew an image where the cursor rectangle is supposed to be. As you can see in the image below it's nowhere near my mouse.

One image of the cursors lag

Another image of the cursors lag

Note how they are in two different places.

How do I fix this horrible lag?

The menu update calls a mouse class to update the mouse position and place it within bounds of the screen. The mouse class also has a rectangle that updates based on the mouse position, but it updates almost 200 pixels away. The mouse moves fine in game, it's just the rectangle is in a weird position

   //This is located in the Mouse Class
    public void Update(GameTime gameTime)
    {
        oldmouse = currentmouse;
        currentmouse = Mouse.GetState();
        Position.X = currentmouse.X;
        Position.Y = currentmouse.Y;
        //Some other boundary code that's not essential
        clickRectangle.X = (int)Position.X;
        clickRectangle.Y = (int)Position.Y;
    }

    // this is located in the menu class

    public void Draw(SpriteBatch spriteBatch)
    {
        spriteBatch.Draw(ArrowTexture, mouseInput.clickRectangle, Color.White);
        //draw other arrows and text
    }

I don't see a problem with the code. Is there something else I have to do?

I should also mention it sometimes draw nearer to the actual cursor and sometimes farther away. The cursor only drew to my actual cursor once before it stopped working.

EDIT: I updated the question with more relevant information. I apologize for not including it earlier.

\$\endgroup\$
7
  • \$\begingroup\$ This part is fine. You're drawing it wrong, probably. \$\endgroup\$ Apr 29, 2012 at 13:27
  • \$\begingroup\$ @JonathanHobbs The drawing was optional, and the lag occurs with or without me drawing the arrow. \$\endgroup\$ Apr 29, 2012 at 13:45
  • \$\begingroup\$ Slightly off topic, but what's changed? Do a diff with the last rev that worked in your source control system. (You ARE using source control, aren't you? :)) \$\endgroup\$
    – 3Dave
    Apr 29, 2012 at 13:53
  • \$\begingroup\$ @DavidLively I unfortunately do not use source control :( if you know of a good one shoot me an email at: thegluestickmam(at)gmail(dot)com I should also mention that the cursor will sometimes draw nearer to my mouse and sometimes farther away. It only worked once for me. \$\endgroup\$ Apr 29, 2012 at 14:46
  • \$\begingroup\$ Beanstalk has free svn repos for closed source projects. \$\endgroup\$
    – 3Dave
    Apr 29, 2012 at 14:53

1 Answer 1

3
\$\begingroup\$

Welp, long after I figured out the problem.

Early in my menu development I inherited the "Game" class from XNA. I forget why, I think it had to do with getting certain method to work or something. I guess I had removed the code that need the inheritance and kept the inheritance which screwed up my update method. It wanted to override it but I didn't do that. Anyway I removed the inheritance and it worked fine.

Doi.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .