![]() |
|
set mouse rate |
thirdy
Member #8,409
March 2007
![]() |
Hi! Is there a function for mouse like set_keyboard_rate(900, 0); in allegro? The mouse in my program produces too many clicks per actual 1 click in the mouse. Thanx! |
James Stanley
Member #7,275
May 2006
![]() |
It doesn't work like that.
|
thirdy
Member #8,409
March 2007
![]() |
Still too fast.
|
Onewing
Member #6,152
August 2005
![]() |
Quote: Still too fast. Ooh, so you're wanting a minimum amount of time a user can click? So if the user is clicking blazing fast, the mouse event that occurs will happen slower? In this situation, you'll have to add some timer logic to your code. ------------ |
thirdy
Member #8,409
March 2007
![]() |
No,here's the situation. One careful left click = three left clicks. I need to make it like a normal mouse click. What could be missing in my code? Can you give me a short program that includes normal mouse, not a crazy one. Thanks! |
Onewing
Member #6,152
August 2005
![]() |
What you have above looks fine, what's the code you use for actually doing something when the mouse button is clicked? ------------ |
thirdy
Member #8,409
March 2007
![]() |
Here's my actual code
Here's also my actual initialization code
|
Onewing
Member #6,152
August 2005
![]() |
The only time the mickey_left and/or mickey_right should be set to FALSE is when the "mouse_b & 1 (or 2)" is not set, like you did in the above code (a few posts up). You're setting it to false in the event, the mouse is still being pressed, so it sets it back to true and then the event sets it back to false. You've effectively defeated the purpose of the mickey_left/right flags. ------------ |
thirdy
Member #8,409
March 2007
![]() |
Actually there was no mickey_left=FALSE; before posting here. But I think there's no effect when you make mickey FALSE, it would still be TRUE in the next loop if mickey is clicked. |
Onewing
Member #6,152
August 2005
![]() |
You're right, I'm reading too skipilly (definitely not a word). Anyway, on the post above (the one where you first said "Still too fast"), notice how when you set mickey_left to true that that only happens once until mouse_b & 1 is not true? That's the logic you need for the actual event to happen. You can either put the event code in that logic above or create another boolean flag for each mouse button event. Setting a flag to be true and then checking if that flag is true is the exact same thing as seeing if mouse_b & 1 is true. ------------ |
ImLeftFooted
Member #3,935
October 2003
![]() |
|
Paul Rowan
Member #8,612
May 2007
![]() |
I don't know if this might help, but in a game i've developed I had the same problem with the keyboard in that when a key was pressed the sprite moved multiple times instead of just the once. The way I solved it was to use a variable for a key delay so that as soon as the key was pressed the key delay variable was set to a number, say 10, then each time through the game loop this variable was reduced by 1 until it reached 0. While ever the key delay variable was more then 0, any key presses for that key were ignored. This slowed down the key presses and you can use a different number in your key delay variable to slow the presses down to what you want. So, I suppose you could use the same method for your mouse button, use a button delay variable so that as soon as the mouse click is registered, the button delay variable is set so that any future clicks will not register until the button delay is back at 0, and reduce the button delay variable each time through the game loop until it gets to 0. |
thirdy
Member #8,409
March 2007
![]() |
Thanks! Finally, 1 click is now exactly one click. Thanks! |
Paul Rowan
Member #8,612
May 2007
![]() |
You're welcome I'm quite a newbie to C and Allegro and only written 1 game so far, but loads of ideas for new ones - is this code for a game ur developing? and if it is what, can u say wot ur developing? |
Onewing
Member #6,152
August 2005
![]() |
I don't think that's a really good idea. One, if you hold down the mouse button the action is going to keep happening every time the variable runs down to 0 (since mouse_b & 1 is still true, the code will register another click). Secondly, it limits how fast a user can click the button. Thirdly, the rate at which a variable decrements to 0 is going to range widely across different computers. For what seems good to you could be horrible elsewhere. ------------ |
Paul whoknows
Member #5,081
September 2004
![]() |
Quote: Thirdly, the rate at which a variable decrements to 0 is going to range widely across different computers. Yes, this is a very bad thing, try to use just flags. ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
thirdy
Member #8,409
March 2007
![]() |
this code satisfy my problem which increments hr by only one per one left click. |
Paul Rowan
Member #8,612
May 2007
![]() |
If you use a timer in your game the delay should reduce at the same rate on different computers. I thought the idea was not to get multiple mouse clicks from 1 click, so if someone holds the mouse button down it should register another click when the delay reached 0 after a short delay, and if the game requires it you should control how fast a user should be able to click a button That's my opinion, but I've only just started developing games and that's the solution i've found so far |
|