Confusing mouse problem

Started by
9 comments, last by Hunter_Ex 18 years, 8 months ago
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
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.
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.
The best thing to do is just choose whatever you think you'd prefer, and go for it. -Promit
Sorry, don't quite follow you there.
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...
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.
The best thing to do is just choose whatever you think you'd prefer, and go for it. -Promit
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.
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 .
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 =)

Raymond Jacobs, Owner - Ethereal Darkness Interactive
www.EDIGames.com - EDIGamesCompany - @EDIGames

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)

This topic is closed to new replies.

Advertisement