Jump to content
  • Advertisement
Sign in to follow this  
MARS_999

Mouse Movement like in RTS game?

This topic is 4975 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
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.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!