I am trying to implement a system, where the cursor (in my case the player's avatar) is always about 1.5 seconds (a configurable interval) behind where the mouse actually is. If I change the cursor's location every time through, I get an emulated mouse cursor with no delay, I'm wondering if there are any pre-canned type of solutions I can throw at this before I "roll-my-own." Source code or even just basic steps you've used would be helpful.
I don't think there are any pre-canned solutions; at least I haven't seen any. But here is the logic to such a thing.
What you essentially want is a queue of mouse positions and timestamps. So define an object, let's call it
MousePositionSnapshot, which has two members,
position (or separate x,y if you want). And then define your queue of
MousePositionSnapshots. Each update, make a new MousePositionSnapshot with the current timestamp and the current position of the mouse, and push it onto the head of the queue. Then peek at the tail of the queue to see if the timestamp is delayed enough for you, and if so, pop it off the end of the queue and move the emulated cursor to the given position.
Or, if you have a fixed framerate, you could skip the timestamp since you know how far apart each update is, and just keep your mouse lag in terms of number of updates; if the queue is smaller in length than that amount of updates then don't pop-and-move, otherwise just pop and move the emulated mouse each frame.
Ricket's answer was my first idea too. If you draw all the mouse pointers in your queue you get a nice trail as well. Another option would be to linearly interpolate your detected mouse position and the actual mouseposition, that way it will gravitate towards the mouseposition with a delay, but it won't actually follow the exact path the mouse travelled. They both achieve the same (configurable delay for the mouse to catch up) but in a decidedly different visual fashion.