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

Getting Gaming With Rubygame

By

Once you have a Surface object with an image, and a screen object to show it on, you can start drawing things to the screen. Drawing one surface to another is called "blitting," which, if you'll remember, is short for block image transfer. The word "blit" comes from the early days of PC game programming, and the name just stuck. You can think of blitting as painting or drawing--it's all the same thing.

The blit method takes two arguments. The first argument is the target surface to blit to, which, in this case, is the screen. The second argument is the coordinates on the target surface to blit to. Since this is a background image, the top-left corner (or coordinates 0,0) will do just fine. Because the background image is the same size as the screen, it will cover the entire screen. Though the blit method can take more arguments (for example, you can blit only part of a surface onto another surface), you don't need to worry about them right now.

The image used was taken from NASA's Astronomy Picture of the Day. Many images there are public domain and can be used in your games. See the "About Image Permissions" section of this page for more information about which images from APOD you can use without special permission.

 # Draw the background onto the screen
 background.blit( screen, [0,0] )
 
 # Show the screen on the monitor
 screen.update
 
  1. About.com
  2. Technology
  3. Ruby
  4. Tutorials
  5. Game Programming
  6. Displaying Images

©2014 About.com. All rights reserved.