|
Mouse button code problem - Doing something when clicked. |
Durnus
Member #7,997
November 2006
|
This may not be as simple as it sounds. I have (tried to) made a class for a game where it needs to sense a click. Not a click every loop, but once when it is clicked. I have made a class, and since it is kinda hard to explain, I'll post the code. main.cpp
controlhandler.h
controlhandler.cpp
There are no compile errors, it just doesn't work like it would be expected to. Please help me, this could be a cool game.
|
Kris Asick
Member #1,424
July 2001
|
This is what is called "overcomplication". In other words, the following code will likely work the way you want. Just replace your entire controlhandler.cpp with this:
Much simpler. As I understand it, you're trying to detect the moment when the mouse button has been released as a single click. I believe this will do that. . --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
HardTranceFan
Member #7,317
June 2006
|
Scrap that, spotted a flaw straight away. And Kris beat me to it. -- |
Durnus
Member #7,997
November 2006
|
Wow, that works perfectly! Thanks! Sometimes I overcomplicate things. I'm going to be using this header throughout my games now. Thanks a bundle! EDIT: Dang it... gave credit to wrong person
|
HardTranceFan
Member #7,317
June 2006
|
Wohoo Free cookies Kris, if there's a way to give them to you, let me know. -- |
Durnus
Member #7,997
November 2006
|
Last time (:P) I could edit the post to change it... but it isn't letting me this time. Sorry Kris
|
Peter Wang
Member #23
April 2000
|
if (!mouse_1 && mouse_1_last) return true; else return false;
return (!mouse_1 && mouse_1_last);
|
Durnus
Member #7,997
November 2006
|
Whoa, even more simplicity. I really wish I could change the credit.
|
Kris Asick
Member #1,424
July 2001
|
shrugs Quite frankly, I never pay attention to that "credits" thing for questions asked. Don't worry about it. --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
|