0
\$\begingroup\$

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?

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Just found this post on the net, it kind of reduces the lag, but all resource consumption maxes out, which is not very cool. \$\endgroup\$ Feb 23, 2013 at 13:47
  • \$\begingroup\$ could it just be your computer or are you sure its a frame rate issue? \$\endgroup\$ Feb 23, 2013 at 17:21
  • \$\begingroup\$ 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. \$\endgroup\$ Feb 23, 2013 at 17:23
  • 1
    \$\begingroup\$ You could try and predict where the mouse position will be in the next frame by using the position from the previous two frames and then set the current frame to that future prediction. Although this may create noticeable lag when a harsh change in direction or velocity is applied to the mouse. I have never noticed this problem on my computer though, is there any chance that your system is locking up or not powerful enough. I know there will always be a little lag but its not usually noticeable. \$\endgroup\$
    – Ree
    Feb 24, 2013 at 2:11
  • 1
    \$\begingroup\$ Use hardware cursor, thats how most of games do it. You can change windows cursor to anything you want, via some winapi call (SetCursor) probably. And then use Game.IsMouseVisible = true to show it \$\endgroup\$
    – Kikaimaru
    Feb 24, 2013 at 8:16

1 Answer 1

2
\$\begingroup\$

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.

\$\endgroup\$
5
  • \$\begingroup\$ 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. \$\endgroup\$ Feb 24, 2013 at 9:35
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Feb 24, 2013 at 11:27
  • \$\begingroup\$ 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. \$\endgroup\$ Feb 24, 2013 at 11:53
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ Feb 24, 2013 at 12:28
  • \$\begingroup\$ 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. \$\endgroup\$ Feb 24, 2013 at 12:54

You must log in to answer this question.

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