Class: DXRuby::Tiled::Tilesets
- Inherits:
-
Object
- Object
- DXRuby::Tiled::Tilesets
- Defined in:
- lib/dxruby_tiled/tilesets.rb
Instance Attribute Summary collapse
-
#tile_bottom ⇒ Object
readonly
Returns the value of attribute tile_bottom.
-
#tile_left ⇒ Object
readonly
Returns the value of attribute tile_left.
-
#tile_right ⇒ Object
readonly
Returns the value of attribute tile_right.
-
#tile_top ⇒ Object
readonly
Returns the value of attribute tile_top.
-
#tiles ⇒ Object
readonly
Returns the value of attribute tiles.
Instance Method Summary collapse
- #[](num) ⇒ Object
- #animate ⇒ Object
- #delayed_dispose ⇒ Object
- #dispose ⇒ Object
- #disposed? ⇒ Boolean
- #gid_adjusted_by_source(gid, source) ⇒ Object
-
#initialize(data, map) ⇒ Tilesets
constructor
A new instance of Tilesets.
Constructor Details
#initialize(data, map) ⇒ Tilesets
Returns a new instance of Tilesets.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dxruby_tiled/tilesets.rb', line 6 def initialize(data, map) @last_time = 0 @tiles = {} dummy_tile = Tile.new(DXRuby::Image.new(map.tile_width, map.tile_height), 0, 0, 0) def dummy_tile.render(x, y, target = DXRuby::Window, z_index = 0); end def dummy_tile.draw(x, y, target = DXRuby::Window, z_index = 0); end @tiles[0] = dummy_tile @tiles.default = dummy_tile @animations = [] @tilesets = data.map { |tileset| Tileset.new(tileset, map) } hex = map.orientation == HexagonalLayer @tilesets.each do |tileset| gid = tileset.firstgid tileset.tiles.each_with_index do |tile, i| next unless tile @tiles[gid + i] = tile range = hex ? 1..15 : 1..7 k = hex ? 0x10000000 : 0x20000000 range.each do |j| tileid = j * k + gid + i @tiles[tileid] = FlippedTile.new(tile, tileid, hex) end end tileset.animations.each { |i| @animations.push(gid + i) } end @tile_left = @tiles.values.map { |tile| tile.offset_x }.min @tile_top = @tiles.values.map { |tile| tile.offset_y }.min @tile_right = @tiles.values.map { |tile| tile.offset_x + tile.width }.max @tile_bottom = @tiles.values.map { |tile| tile.offset_y + tile.height }.max end |
Instance Attribute Details
#tile_bottom ⇒ Object (readonly)
Returns the value of attribute tile_bottom.
4 5 6 |
# File 'lib/dxruby_tiled/tilesets.rb', line 4 def tile_bottom @tile_bottom end |
#tile_left ⇒ Object (readonly)
Returns the value of attribute tile_left.
4 5 6 |
# File 'lib/dxruby_tiled/tilesets.rb', line 4 def tile_left @tile_left end |
#tile_right ⇒ Object (readonly)
Returns the value of attribute tile_right.
4 5 6 |
# File 'lib/dxruby_tiled/tilesets.rb', line 4 def tile_right @tile_right end |
#tile_top ⇒ Object (readonly)
Returns the value of attribute tile_top.
4 5 6 |
# File 'lib/dxruby_tiled/tilesets.rb', line 4 def tile_top @tile_top end |
#tiles ⇒ Object (readonly)
Returns the value of attribute tiles.
4 5 6 |
# File 'lib/dxruby_tiled/tilesets.rb', line 4 def tiles @tiles end |
Instance Method Details
#[](num) ⇒ Object
38 39 40 |
# File 'lib/dxruby_tiled/tilesets.rb', line 38 def [](num) @tiles[num] end |
#animate ⇒ Object
42 43 44 45 46 47 |
# File 'lib/dxruby_tiled/tilesets.rb', line 42 def animate() return if @last_time == DXRuby::Window::running_time @last_time = DXRuby::Window::running_time @animations.each { |i| @tiles[i].animate!(@last_time) } end |
#delayed_dispose ⇒ Object
58 59 60 61 |
# File 'lib/dxruby_tiled/tilesets.rb', line 58 def delayed_dispose() @tilesets.each_value { |tileset| tileset.delayed_dispose() } @tiles[0].image.delayed_dispose() end |
#dispose ⇒ Object
53 54 55 56 |
# File 'lib/dxruby_tiled/tilesets.rb', line 53 def dispose() @tilesets.each_value { |tileset| tileset.dispose() } @tiles[0].image.dispose() end |
#disposed? ⇒ Boolean
63 64 65 |
# File 'lib/dxruby_tiled/tilesets.rb', line 63 def disposed?() @tiles[0].image.disposed?() end |
#gid_adjusted_by_source(gid, source) ⇒ Object
49 50 51 |
# File 'lib/dxruby_tiled/tilesets.rb', line 49 def gid_adjusted_by_source(gid, source) gid + @tilesets.find { |tileset| tileset.source == source }.firstgid - 1 end |