Sha256: a796b9c9a805aee6e25caad5286a59015d1e192a2b8d811dadbfa5d17556aa5a
Contents?: true
Size: 835 Bytes
Versions: 2
Compression:
Stored size: 835 Bytes
Contents
class Image def initialize(image_name) @image = Image.load(image_name) end def draw(x:, y:, scale: 1) @image.draw(x, y, 0, scale, scale) end def width @image.width end def height @image.height end class << self @@images = {} def load(image_name) locate_image(image_name) end private def locate_image(image_name) return @@images[image_name] if @@images[image_name] puts "Initialize image: '#{image_name}'" base_path = "#{Dir.pwd}/images" file_name = Dir.entries(base_path).find { |e| e.start_with?("#{image_name}.") } raise "Image file not found with name '#{image_name}'" if file_name.nil? @@images[image_name] = Gosu::Image.new("#{base_path}/#{file_name}", { retro: true }) return @@images[image_name] end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
fantasy-0.1.3 | lib/fantasy/image.rb |
fantasy-0.1.1 | lib/fantasy/image.rb |