Rubygame 3: Day 29

Lots of poking around in the guts of events today. Most notable is that I threw out all the keyboard integer constants, as I was talking about a week ago. No more Rubygame::K_QUOTEDBL, hurray!

Likewise for mouse integer constants; I changed them to :mouseN where N is the mouse button number. So, the left mouse is :mouse1, middle is :mouse2, right is :mouse3, wheel-up is :mouse4, and wheel-down is :mouse5. I'm torn between the mouse numbers and the mouse button names. :mouse_left might be nice. The nice thing about the numbered scheme is that it supports an arbitrary number of buttons (got any 10-buttoned mice lying around? It'll probably work!). Also, it doesn't make any assumptions about which button is where (e.g., mouse buttons 4 & 5 are usually, but sometimes not, mouse wheel-up and wheel-down).

Next I'll probably get rid of the Surface/Screen integer flags, as I also mentioned. Death to the integer constants! Long live the symbol!

And now for something completely different...

I had an idea for making it even more convenient to add an event hook to sprites/scenes. I figure that, by and large, most event hooks that developers will create are of the form "press this -> character does that". So, why not have a factory function to create new event hooks that call a method in the sprite? Something like this:

sprite.keydown_hook(:up, :jump)

Wolud be equivalent to:

  :owner => sprite,
  :trigger => KeyDownTrigger(:up),
  :action => MethodAction(:jump)

Which means "when the user presses the up arrow, call sprite#jump".

Of course, there wolud be similar factory functions for mouse clicks, etc.


Jonathan submitted a comment on #

Not quite related to this particular post, but to rubygame 3 in general:

What’s the status of Ruby 1.9 compatibility? One of the first things I would like to do in Ruby 1.9 is use rubygame… :)

ippa submitted a comment on #

Why not have the constants reflect the “real names”:

You would say “left mouse button” right? So why not :left_mouse_button.

When ppl get that basic principle there’s no more guessing/looking up constants.

If you must number them, :first_mouse_button, :second_mouse_button etc.. or maybe :mouse_button_1, :mouse_button_2..

There’s there a possibility or repeating the “misstake” of creating shorthand contants that feel natural to the creator instead of just taking what’s there allready, their natural names? (converted to symbols)

my 2 cents :)

.. and I like your second idea.

[Fixed your underscores for you. I’m going to look into disabling the underscores-to-italics markup when I get some time, but for now put one backslash in front of it. –jacius]

ippa submitted a comment on #

.. the markup ate my underscores.

John Croisant submitted a comment on #

@Jonathan: I haven’t done anything specifically towards 1.9 compatibility; but I also haven’t checked to see whether it works as-is.

I’m wary of chasing a “moving target” (API that is potentially in flux). But, if someone wants to check that out and file some reports on things that don’t work, there’s a good chance I’ll investigate them. ;)

John Croisant submitted a comment on #

@ippa: You have a very good point about natural names. I’ll give it some serious consideration.

denor submitted a comment on #


I like the work so far; porting to Rubygame3 has been pretty easy. Changing out the keyboard constants has required the most work so far, and I’m running into the trouble you mentioned on day 22. If I want to check for backslashes, :\ isn’t working for me. Though I am liking how my code looks like emoticons :)

Also, this change breaks Rubygame::Event::key_name, but since all I have to do is use the symbol, I’m not sure I care :)

Have something interesting to add to the discussion? Email your thoughtful comments to