Moar questions!
In my game I use the mouse cursor to aim. I've looked around for ways to show a custom mouse cursor in-game, but all I can find is the following method:
- Keep track of the mouse's position during Update calls
- Draw a cursor at its position during Draw calls
The problem with this is that it limits the mouse's responsiveness to the framerate, which causes it to feel sluggish. The effect can easily be seen by turning on the IsMouseVisible property so that the game shows the default hardware mousecursor as well. If I move the cursor around, at 60fps, my homemade cursor seems to lag behind the windows cursor, following it around across the screen.
So what I've done is hook up an event to the mouse's movement. As a test I removed the position tracking from the Update method and put it in my event instead, which worked nicely:
void hook_MouseMove(object sender, MouseHookEventArgs e)
{
Vector2 windowposition;
windowposition = new Vector2(this.Window.ClientBounds.Left, Window.ClientBounds.Top);
mousePosition.X = e.X;
mousePosition.Y = e.Y;
mousePosition -= windowposition;
}
Now I'd also like to draw the mouse cursor on the window/screen at this point. Ideally, I'd plot the cursor directly to the screen instead of the backbuffer, using damage repair so as to not leave a messy trail.
Unfortunately I am at a loss at how to do this, or if it is even possible within the framework. So my question is how do I do a quick plotting of my mousecursor to the screen, or is there another way to add a fast and responsive custom mousecursor image to my game?
Edit:
After some more experimenting, it seems that the SynchronizeWithVerticalRetrace is causing me grief. The game will draw the screen, then wait for the next retrace to copy it all to the front buffer - and this minimal wait time is causing the cursor to lag. At the moment I'm using the workaround of just turning off retrace synching, which works as long as my framerate stays high enough to avoid "tearing".
Perhaps there's some way to respond to the retrace or the game's final draw-to-front-buffer step where I can quickly plot in the cursor somehow.. :)