Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
This part is fine. You're drawing it wrong, probably. –  doppelgreener Apr 29 '12 at 13:27
    
@JonathanHobbs The drawing was optional, and the lag occurs with or without me drawing the arrow. –  Thegluestickman Apr 29 '12 at 13:45
    
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? :)) –  David Lively Apr 29 '12 at 13:53
    
@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. –  Thegluestickman Apr 29 '12 at 14:46
    
Beanstalk has free svn repos for closed source projects. –  David Lively Apr 29 '12 at 14:53

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.