O'Reilly logo

Learn Game Programming with Ruby by Mark Sobkowicz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required