Class: RubyArmor::SpriteSheet

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ruby_armor/sprite_sheet.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, width, height, tiles_wide = 0) ⇒ SpriteSheet

Returns a new instance of SpriteSheet.



16
17
18
19
# File 'lib/ruby_armor/sprite_sheet.rb', line 16

def initialize(file, width, height, tiles_wide = 0)
  @sprites = Image.load_tiles($window, File.expand_path(file, Image.autoload_dirs[0]), width, height, false)
  @tiles_wide = tiles_wide
end

Class Method Details

.[](file, width, height, tiles_wide = 0) ⇒ Object



8
9
10
11
12
13
# File 'lib/ruby_armor/sprite_sheet.rb', line 8

def [](file, width, height, tiles_wide = 0)
  @cached_sheets ||= Hash.new do |h, k|
     h[k] = new(*k)
  end
  @cached_sheets[[file, width, height, tiles_wide]]
end

Instance Method Details

#[](x, y = 0) ⇒ Object



21
22
23
# File 'lib/ruby_armor/sprite_sheet.rb', line 21

def [](x, y = 0)
  @sprites[y * @tiles_wide + x]
end