Wednesday, June 4, 2008

Adventures in Programming: Double Clicking

While working on the next version of MTG Forge, which will be called “AI Mage”, I encountered a little snafu. The graphic library (PyGame) which also handles all events doesn’t seem to have a “double click” event. While double-clicking is common when using Windows, I guess it is rare when it comes to videogames. So I was left with a problem, how could I simulate double-clicking? I couldn’t just use single-clicking since I allow the user to rearrange the cards. So what was I going to do?

I don’t know if this solution is optimal or not, but I substituted right-clicking instead. So you use the left mouse button to move a card and the right button to play the card. Hopefully this will eliminate the nuisance of accidentally playing a card, which is very common with Magic Online.

I could have tried to devise a way to measure the time between clicks, so that I could turn a single click into a double click but I wanted a simple solution. On a side note, I was hoping that AI Mage could run on a Macintosh, but I don’t know if they use a two button mouse. I know the old Macs used only a one button mouse.

The joys of programming, oh how I love (and sometimes hate) thee. If my brain can concentrate well enough, I actually spend my time programming instead of playing videogames.

6 comments:

Ian said...

Handling double clicking shouldn't be too hard.

I haven't looked at the code, but if you're grabbing input using event.get, then you should be able to assign a timestamp to each event.

Then you just need:

def handle_click(click):
if (distance_between(click, last_click) < dist_threshold) and time_between(click, last_click) < time_threshold):
handle_double_click(click)
else:
handle_single_click(click)
last_click = click

Ian said...

Ok. All my formatting was screwed up. But you get the idea. You only need to save one past click and check for time and distance to determine if the click is a "double"

The Two said...

to do double clicks just slap in a timer.time() that executes different things if there is another click before the timer hits some arbiraty number...

but as a gamer...double clicks are awkward. I would much more preferable to do a right click menu or even have buttons at the bottom of the card/menu to execute different things. But that's my opinion its your game.

Anonymous said...

I think you should reverse the buttons. Left mouse button (the most common action) should be for playing the card, and right mouse button for rearranging cards (which isn't primary to the game function)

Forge said...

Thanks for your comments. Mostly I just had to make a decision. It can be changed later. Because how the cards are drawn on the screen you WILL be moving them around, because the program doesn't put a new card into an "empty" space.

Hopefully my program will be flexible so the user can choose what they want the left or right button, or what double clicking means.

Anonymous said...

Here's one for ya!
On mouse over (hovering) a button should appear on the bottom of the card with the name play card instead of double click

And one more !
If a card is played the rest of the cards should regroup! or leave an empty space and at the next draw phase put the new card there to fill
the gap!
Obviously I know nothing about programing but i've got plenty of ideas! :D