Sign in to follow this  

Mouse Movement like in RTS game?

This topic is 4727 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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???

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4727 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this