Class: Gosling::ImageLibrary

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/gosling/image_library.rb

Overview

A cached Gosu::Image repository.

Constant Summary collapse

@@cache =
{}

Class Method Summary collapse

Class Method Details

.get(filename) ⇒ Object

When passed the path to an image, it first checks to see if that image is in the cache. If so, it returns the cached Gosu::Image. Otherwise, it loads the image, stores it in the cache, and returns it.



16
17
18
19
20
21
22
# File 'lib/gosling/image_library.rb', line 16

def self.get(filename)
  unless @@cache.has_key?(filename)
    raise ArgumentError.new("File not found: '#{filename}' in '#{Dir.pwd}'") unless File.exists?(filename)
    @@cache[filename] = Gosu::Image.new(filename, tileable: true)
  end
  @@cache[filename]
end