Class: Gosu::Tiled::Tilesets
- Inherits:
-
Object
- Object
- Gosu::Tiled::Tilesets
- Defined in:
- lib/gosu_tiled/tilesets.rb
Instance Method Summary collapse
- #get(index) ⇒ Object
-
#initialize(window, data, data_dir) ⇒ Tilesets
constructor
A new instance of Tilesets.
- #properties(index) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(window, data, data_dir) ⇒ Tilesets
Returns a new instance of Tilesets.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/gosu_tiled/tilesets.rb', line 4 def initialize(window, data, data_dir) @root_dir = data_dir @window = window @data = data @tilesets = {} @data.each do |t| tileset = Gosu::Image.load_tiles( @window, File.join(data_dir, t['image']), t['tilewidth'], t['tileheight'], true) @tilesets[t['firstgid']] = { 'data' => t, 'tiles' => tileset } end end |
Instance Method Details
#get(index) ⇒ Object
23 24 25 26 27 |
# File 'lib/gosu_tiled/tilesets.rb', line 23 def get(index) return empty_tile if index == 0 || index.nil? key = closest_key(index) @tilesets[key]['tiles'][index - key] end |
#properties(index) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/gosu_tiled/tilesets.rb', line 29 def properties(index) return {} if index == 0 key = closest_key(index) props = @tilesets[key]['data']['tileproperties'] return {} unless props props[(index - key).to_s] end |
#size ⇒ Object
19 20 21 |
# File 'lib/gosu_tiled/tilesets.rb', line 19 def size @data.size end |