Class: Okami::Image

Inherits:
Gosu::Image
  • Object
show all
Includes:
DrawMethods
Defined in:
lib/okami/image.rb

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from DrawMethods

#draw_using

Class Attribute Details

.load_pathObject

The directory to load the images from



32
33
34
# File 'lib/okami/image.rb', line 32

def load_path
  @load_path
end

.tileableObject

Default value for wether the images should be tileable or not



30
31
32
# File 'lib/okami/image.rb', line 30

def tileable
  @tileable
end

Class Method Details

.load(relative_path, options = nil) ⇒ Object

Character::Will load and cache even if it’s already cached



51
52
53
54
55
56
57
58
59
60
# File 'lib/okami/image.rb', line 51

def load relative_path, options=nil
  image_path = File.join(@load_path, relative_path)
  
  Okami::ImageCache[relative_path] = 
    if options
      new_by_options options
    else
      new $window, image_path
    end
end

.load_tiles(relative_path, tile_width, tile_height, tileable = @tileable) ⇒ Object

Character::Will load and cache even if it’s already cached



77
78
79
80
81
82
83
84
85
86
# File 'lib/okami/image.rb', line 77

def load_tiles relative_path,
               tile_width,
               tile_height,
               tileable=@tileable
               
  image_path = File.join(@load_path, relative_path)
  tiles = super $window, image_path, tile_width, tile_height, tileable
  tiles.each { |tile| tile.extend Okami::DrawMethods }
  Okami::ImageTileCache[relative_path] = tiles
end

.new_by_options(options) ⇒ Object



62
63
64
65
66
# File 'lib/okami/image.rb', line 62

def new_by_options options
  tileable = options[:tileable] || @tileable
  src_rect = options[:src_rect]
  new $window, image_path, tileable, *src_rect
end

.require(relative_path, options = nil) ⇒ Object Also known as: []

Character::Will cache the images so they’re only loaded once.



44
45
46
47
# File 'lib/okami/image.rb', line 44

def require relative_path, options=nil
  Okami::ImageCache[relative_path] ||
  load(relative_path, options)
end

.require_tiles(relative_path, tile_width = nil, tile_height = nil, tileable = @tileable) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/okami/image.rb', line 68

def require_tiles relative_path,
                  tile_width=nil,
                  tile_height=nil,
                  tileable=@tileable
  Okami::ImageTileCache[relative_path] ||
  load_tiles(relative_path, tile_width, tile_height, tileable)
end