Game Programming With Ruby

After over a year of inactivity I’m back with a new tutorial. Hopefully it won’t take me so long to write the next one. Only time will tell.

My latest tutorial is called Getting Started With Rubygame. It’s a very brief introduction to the Rubygame library. Rubygame is a wrapper for SDL.

Check out the tutorial and let me know what you think.

4 Responses to “Game Programming With Ruby”


  • Hi! I’m a newbie on Ruby and I’m trying to understand the basics of rubygame, using your example and expanding it. I have a problem trying to intercept a simple mousePress event. The interpreter seems to not recognize the MouseButtonEvent class that I use in a cast is_a to intercept the mouse event. In some other files,other events are intercepted that way… (like KeyDownEvent, QuitEvent)

    here I programmed a simple queue loop which will return if a mouse button is pressed:

    queue.each do|e|
    return if e.is_a?(Rubygame::MouseButtonEvent)
    end

    the interpreter tells me this:

    game.rb:261:in `main_loop’: uninitialized constant Rubygame::MouseButtonEvent (NameError)
    from C:/Ruby/lib/ruby/gems/1.8/gems/rubygame-2.6.2/lib/rubygame/queue.rb:110:in `_old_each’
    from C:/Ruby/lib/ruby/gems/1.8/gems/rubygame-2.6.2/lib/rubygame/queue.rb:110:in `each’
    from game.rb:260:in `main_loop’
    from game.rb:256:in `loop’
    from game.rb:256:in `main_loop’
    from game.rb:294

    after some research, I tried to put this before the queue loop:

    queue.enable_new_style_events

    no effect… I’m feeling kinda helpless. Any advice would be very welcome

    Best regards

    François

  • François,

    Try changing Rubygame::MouseButtonEvent to Rubygame::MouseDownEvent (or Rubygame::MouseUpEvent)

    It should work after that.

    Tony

  • ok, problem solved :

    queue = EventQueue.new
    queue.enable_new_style_events #important
    queue.each do|e|
    return if e.is_a?(Rubygame::Events::QuitRequested)
    puts ‘pressed’if e.is_a?(Rubygame::Events::MousePressed)
    end

    voila!

  • Thanx Tony

Leave a Reply