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 trying to understand if this is avoidable, or it's something I just have to deal with when using XNA.

I made a new game project and loaded simple 16×16 cursor image to draw each frame at exact cursor coordinates, but even with TargetElapsedTime set to 1f/1000f and IsFixedTimeStep = false, it seems as if the game does all calls one host frame late. Game cursor is always visible a few pixels behind the real one.

Can this be fixed somehow, or is there no way around it?

share|improve this question
    
Just found this post on the net, it kind of reduces the lag, but all resource consumption maxes out, which is not very cool. –  user1306322 Feb 23 '13 at 13:47
    
could it just be your computer or are you sure its a frame rate issue? –  Potato Feb 23 '13 at 17:21
    
I don't know what kind of issue this truly is, but I know that if unlocked, empty XNA game runs at about 6000 fps. –  user1306322 Feb 23 '13 at 17:23
    
This happens to me in java too... I remember someone posting this same question a while ago and found a way to reduce it but not eliminate it. –  Savlon Feb 23 '13 at 21:03
    
Unlocking framerate might help, as it did in my case, but surely there must be a cleaner way to do this. –  user1306322 Feb 23 '13 at 21:10
show 2 more comments

1 Answer

up vote 1 down vote accepted

You cannot solve this problem, but you can work around it by hiding the Windows mouse cursor and drawing your own. Or replacing the Windows cursor with your own.

I explain the cause of the problem in detail in this answer. Basically Windows draws with the hardware cursor - which has an extremely low latency path from mouse-to-output. Any cursor you draw with XNA will have some latency behind the real cursor. The majority of this latency is caused by double-buffering of your graphics.

share|improve this answer
    
It's kind of lame this kind of problem can't be solved for a game engine. There are many FPS games that have a terrible problem of processing user input with a noticeable lag of 50-250 ms which makes them unplayable for some people. I don't want my game to be one of them. Guess I'll have to switch from XNA to something else. –  user1306322 Feb 24 '13 at 9:35
    
It's not really an XNA problem (difficulty disabling double-buffering aside - generally you don't want to). XNA is basically DirectX, so what would you switch to?? John Carmack just recently wrote about input-to-output latency in the context of VR systems. But it's still relevant to the general case. Most latency comes from the GPU pipeline, unless you deliberately add pipelining into your own code. The article has a few tricks (usable in XNA) to reduce latency. Ridiculous 250ms latency is probably a driver bug. –  Andrew Russell Feb 24 '13 at 11:27
    
I just think that if there was a way to instantly call input update when any button state is changed, this would minimize the latency between user input and processing to acceptable time. Latency between processing and output is usually fine. It's the processing which is usually late. –  user1306322 Feb 24 '13 at 11:53
    
Are you sure about that? A game running smoothly and polling input at 60FPS should have less than 16ms latency between any key being pressed and that game being able to handle that input. –  Andrew Russell Feb 24 '13 at 12:28
    
Problem is games rarely always run smoothly, and when it comes to that it's a pity when some key presses get lost or are processed too late. –  user1306322 Feb 24 '13 at 12:54
add comment

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.