1. Home
  2. Computing & Technology
  3. Ruby

Getting Gaming With Rubygame

By Amanda & Michael Morin, About.com

2 of 5

Setting up Autoloading

The easiest way to load an image into a surface is to set up Rubygame's autoloading. When autoloading is enabled, Rubygame will search a number of user-defined directories for the files you want to load. When the files are loaded into memory, they stay in memory until the end of the program, so future references to the same image will not require the image be reloaded from the hard drive.

Setting up autoloading is easy. Simply assign a list of directories to Surface.autoload_dirs. Once that's done, you can use the index operator on the Surface class itself to load images into surfaces. To get the directory your program is in (which may or may not be the directory from which the program was actually run), you can use the special variable __FILE__.

# Set up automatic loading of images and sounds
resources_dir = File.dirname( __FILE__ ) + "/data"
Surface.autoload_dirs = [ resources_dir ]
Explore Ruby
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Ruby
  4. Tasks & Scripts
  5. Game Programming
  6. Setting up Autoloading

©2009 About.com, a part of The New York Times Company.

All rights reserved.