Class: EhbGameLib::Palettes::Sprite

Inherits:
Object
  • Object
show all
Defined in:
lib/ehb_game_lib/palettes/sprite.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_file(file_path) ⇒ Object



10
11
12
# File 'lib/ehb_game_lib/palettes/sprite.rb', line 10

def from_file(file_path)
  new(::Magick::Image.read(file_path.to_s).first)
end

.to_gosu_image_optionsObject



14
15
16
# File 'lib/ehb_game_lib/palettes/sprite.rb', line 14

def to_gosu_image_options
  { retro: true, tileable: true }
end

Instance Method Details

#gosu_imageObject

Returns Gosu::Image.

Returns:

  • Gosu::Image



24
25
26
27
28
29
30
# File 'lib/ehb_game_lib/palettes/sprite.rb', line 24

def gosu_image
  @gosu_image ||= begin
    the_path = '/tmp/temp_magick_image.png'
    magick_image.write(the_path)
    ::Gosu::Image.new(the_path, self.class.to_gosu_image_options)
  end
end

#palette_image(palette) ⇒ EhbGameLib::Palettes::Sprite



33
34
35
36
37
38
39
# File 'lib/ehb_game_lib/palettes/sprite.rb', line 33

def palette_image(palette)
  r = magick_image.dup
  r.colors.times.each do |index|
    r.colormap(index, palette.color(index).magick_pixel)
  end
  self.class.new(r)
end