Drawing The MouseThere's two main philosophies behind drawing the mouse cursor. If you know that your entire screen will be refreshed with new pixel data every frame, you can simply blt the mouse cursor at its new absolute position, and be done with it. A better, solution, however, is to grab a copy of the pixel data under the mouse cursor before you blt it, then, when the mouse moves, you erase your old blt by blting your saved pixel data back. I prefer the second method. I'm not going to go into the gritty details of blitting surfaces and all that; you should know how to do that. Threads and TailsIf you don't mind multithreading, there's a better way to deal with the mouse than what's described here. The method here is a one thread method, which polls the mouse every frame. Good for high frame rates, but not so good for low frame rates – the mouse cursor will appear "sluggish." The best way to deal with the mouse is to start a separate "mouse-rendering" thread, which continually monitors WM_MOUSEMOVE messages, and takes care of updating and bltting the mouse cursor each time the mouse is moved. The advantage to multithreading the mouse pointer in this manner is that your mouse will still be fluid regardless of how slow your game's frame rate is. Having a separate thread for your mouse will make the game feel responsive, regardless of frame rate. Also, it should be obvious to you by now how to create mouse trails. Keep the last several (five or ten) mouse cursor positions in an array. Whenever the mouse moves, discard the oldest coordinate, move all the other coordinates down one slot, and put the newest coordinate in the top slot. Then, if you want to get extra fancy, use alpha-blitting to render the old coordinates with more transparency than the newer ones.
|
||||||||||||||||||||