Jump to content
  • Advertisement
Sign in to follow this  
kzar

Confusing mouse problem

This topic is 4850 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

Before I start my game I have thought of a problem I need to figure out first. Say if I wanted to use mouse movement to control somthing, maybe I want the object to follow the mouse exactly or speed up gradually but what happens when the mouse cursor gets to the edge of the window? Also what happens when I pause / unpause the game? For example breakout you want the paddle to follow the mouse exactly but if I paused the game, moved the mouse and unpaused it would suddenly jump. For another example say I want to controll a marble rolling around. Its still and then when I move the mouse left it should increase in speed depending on how far left I move the mouse and then when I move the mouse right it slows down again, stops and then starts rolling right. But how could I do this without worying about the cursor leaving the window? I will be using C and SDL by the way incase that effects how I should do it. (Although I'm looking for a way of doing it rather than someone coding it for me) Anyway thanks for the help, David

Share this post


Link to post
Share on other sites
Advertisement
How does this sound, the cursor is put in the middle of the screen, when the mouse is moved I use the position relative to the center and then reset the cursor to the middle again.

Share this post


Link to post
Share on other sites
Um, give it it's own mouse? In other words: Make the mouse so that the mouse is attached to the paddle, not the paddle to the mouse.

Share this post


Link to post
Share on other sites
What you need is the Mickeys of the mouse, the actual travelled units, and not the absolute mouse position, to control your in-game objects.

See if this link helps you.

In case you still have doubts, I'll home later on, so ask away...

Share this post


Link to post
Share on other sites
Quote:
Original post by kzar
Sorry, don't quite follow you there.


That's about as simple as I can put it.

Make the mouse go wherever the paddle goes. If the mouse moves then the paddle moves. Actually, I was wrong I meant that you should link them both together! So that the mouse follows the paddle and the paddle follows the mouse.

Share this post


Link to post
Share on other sites
Quote:
Original post by orcfan32
Quote:
Original post by kzar
Sorry, don't quite follow you there.


That's about as simple as I can put it.

Make the mouse go wherever the paddle goes. If the mouse moves then the paddle moves. Actually, I was wrong I meant that you should link them both together! So that the mouse follows the paddle and the paddle follows the mouse.


Yes but that has the problems as I described in my original post.

Share this post


Link to post
Share on other sites
Quote:
Original post by Prozak
What you need is the Mickeys of the mouse, the actual travelled units, and not the absolute mouse position, to control your in-game objects.

See if this link helps you.

In case you still have doubts, I'll home later on, so ask away...


Great thanks, I did a google for Mickeys and I found this post http://www.flipcode.org/cgi-bin/fcmsg.cgi?thread_show=8810 .

Share this post


Link to post
Share on other sites
As Prozak said,

you only want to know about a mouse's change in position, not it's absolute position.

In order to calculate a change (a delta) you need to know where the mouse was before and then after the move.

for instance


deltaX=lastPosition.x-newPosition.x;
deltaY=lastPosition.y-newPosition.y;

this can be acomplished in a number of ways, but the simplest is probably polling((asking) GetCursorPos under WIN32), the mouse where it's position is, and storing it as the last position.

Every time you poll the mouse, you check what the last position was and calculate the deltas (changes in motion), then your new mouse position becomes your old mouse position.

Hope that helps =)

Share this post


Link to post
Share on other sites
Quote:
Original post by EDI
As Prozak said,

you only want to know about a mouse's change in position, not it's absolute position.

In order to calculate a change (a delta) you need to know where the mouse was before and then after the move.

for instance


deltaX=lastPosition.x-newPosition.x;
deltaY=lastPosition.y-newPosition.y;

this can be acomplished in a number of ways, but the simplest is probably polling((asking) GetCursorPos under WIN32), the mouse where it's position is, and storing it as the last position.

Every time you poll the mouse, you check what the last position was and calculate the deltas (changes in motion), then your new mouse position becomes your old mouse position.

Hope that helps =)


Yep thanks, and the link I found shows you how to make it carry on even if it passes the edge of the screen, so I'm sorted now.

(Your game is looking really good by the way)

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!