Draw the Ruby

The first thing you’ll draw in your empty window is the ruby. You have the ruby image file in your game folder, but your WhackARuby class doesn’t know about it yet. Gosu supplies you with a class for handling images, named Gosu::Image. In your initialize method, create an instance of Gosu::Image and load your ruby image into it.

Add a line of code at the end of the initialize method that loads the image file into your game. Make sure this line is inside the initialize method, right after the line where the caption is set, and before the end that ends the initialize method.

Instance variable names always start with an @ symbol and are variables that are accessible from all the methods in a class. To create the variable in the ...

Get Learn Game Programming with Ruby now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.