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

Loading and Displaying Your Sprite

By

2 of 5

Turning An Image Into a Sprite

Loading the image is just like loading the image for the background. Simply set up your autoload directories and using the Surface['filename'] idiom to load the image file into a surface.

However, since multiple copies of a sprite can exist on the screen, it's time to start wrapping things in some abstractions. Rubygame provides a Sprite mixin to make this easy and provides a number of useful methods (such as draw) to draw the sprite onto the screen. In order to make a class into a sprite, the class must provide at least two methods or instance variables called image and rect. The image is the graphic to display, the rect is the graphic's position and dimensions in the game world.

  1. About.com
  2. Technology
  3. Ruby
  4. Tutorials
  5. Game Programming
  6. Turning Images Into Sprites

©2014 About.com. All rights reserved.