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

Getting Gaming With Rubygame


Once autoloading is set up, you can load images on the Surface class itself with the index operator. For example, to load the image file background.png, you could say surface = Surface['background.png']. This is a great little shortcut Rubygame sets up for you, and it makes loading images a snap.

Loaded images should be stored in a variable. Be sure to keep the variable around if you wish to keep any changes you make to the surface object. If the variable goes out of scope or there are no more references to it, the image will still be in memory but any changes you made to it will not be there.

Also note that surfaces can only be loaded after the Screen object has been created. Rubygame needs to know the properties of the screen (bit depth, etc) in order to properly load surfaces. Trying to load a surface before the screen has been created will raise an exception.

  1. About.com
  2. Technology
  3. Ruby
  4. Tutorials
  5. Game Programming
  6. Loading Images

©2014 About.com. All rights reserved.