Mouse Movement like in RTS game?

Started by
5 comments, last by MARS_999 19 years, 3 months ago
How do I make the screen move forward, backwards, left, right by moving my mouse to the end of the screen like they do in RTS games? I can think of one way but seems like a hack? Thanks for the ideas and help.
Advertisement
Never actually done this, but this is how I would do it.

Using left-hand side only (without loss of generality) : pseudo-code:

Each frame:
If mouse-pointer within 5% of total screen width of LHS
Move view frustrum right by amount equal to basic speed * (5 - x), where x is the proportion of the screen width you are close to the edge (obviously you can incorporate these into one step using min/max).

Or more clearly :

screen width is 600
5% is therefore 30.
If mouse is less than 30 pixels from LHS, move screen right at speed * (30 - number of pixels from edge) i.e. 29 pixels away, move at speed, 1 pixel away, move at 29 * speed.

Hope that's clear,
Jim.
Quote:Original post by MARS_999
How do I make the screen move forward, backwards, left, right by moving my mouse to the end of the screen like they do in RTS games? I can think of one way but seems like a hack? Thanks for the ideas and help.


If you can think of a way that gets the job done efficiently, then go ahead and do it by all means! If it gets the job done, do it! [smile]. Regardless JimPrice's method is the same approach I would take.
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
Issue with the above method is in the winProc function the values only get processed when the mouse moves not while its just sitting there? Any ideas on that or is there some really simple item I am missing to get this to work???
Since you're checking it every frame, it will update as to the mouse's position. When it gets out of range of the screen bounds, the world will stop moving.
You will only update the scroll speed in your WM_MOUSEMOVE (e.g. set it to zero if the cursor is nowhere near the egde and set it like JimPrice described if it is) and call your update scrolling function each frame. If the scroll speed is zero then it just does nothing, otherwise it scrolls the map.

Hope this helps,
Pat.
Ok I think I got it working now. Thanks all.

This topic is closed to new replies.

Advertisement