1. Technology
Send to a Friend via Email
You can opt-out at any time. Please refer to our privacy policy for contact information.

The Main Loop


2 of 5

Setting Up Rubygame

Rubygame wraps the SDL graphics library much the same way PyGame does for Python. SDL, being a low-level library, is often quite tedious to program in C or C++; Rubygame wraps these same C functions in an abstracted and high-level Ruby API to make game programming a snap. Though there is still some setup that must be done before you can jump in.

The first step, of course, is to include the rubygame library. This will import all features from the Rubygame library into the Rubygame module. If you don't want to have to prepend all references to Rubygame classes with Rubygame::, then you can also include the Rubygame module into the global namespace. This saves some typing and makes things a little more readable.

If you installed Rubygame as a gem, you should require the rubygems library before the Rubygame library.

#!/usr/bin/env ruby
require 'rubygems'
require 'rubygame'
include Rubygame
  1. About.com
  2. Technology
  3. Ruby
  4. Tutorials
  5. Game Programming
  6. Setting Up Rubygame

©2014 About.com. All rights reserved.