Class: DXRuby::Tiled::Tileset
- Inherits:
-
Object
- Object
- DXRuby::Tiled::Tileset
- Defined in:
- lib/dxruby_tiled/tileset.rb
Instance Attribute Summary collapse
-
#animations ⇒ Object
readonly
Returns the value of attribute animations.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#firstgid ⇒ Object
readonly
Returns the value of attribute firstgid.
-
#margin ⇒ Object
readonly
Returns the value of attribute margin.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#spacing ⇒ Object
readonly
Returns the value of attribute spacing.
-
#tile_count ⇒ Object
readonly
Returns the value of attribute tile_count.
-
#tile_height ⇒ Object
readonly
Returns the value of attribute tile_height.
-
#tile_offset ⇒ Object
readonly
Returns the value of attribute tile_offset.
-
#tile_width ⇒ Object
readonly
Returns the value of attribute tile_width.
-
#tiles ⇒ Object
readonly
Returns the value of attribute tiles.
Instance Method Summary collapse
- #delayed_dispose ⇒ Object
- #dispose ⇒ Object
- #disposed? ⇒ Boolean
-
#initialize(data, map) ⇒ Tileset
constructor
A new instance of Tileset.
Constructor Details
#initialize(data, map) ⇒ Tileset
Returns a new instance of Tileset.
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dxruby_tiled/tileset.rb', line 8 def initialize(data, map) @firstgid = data[:firstgid] || 1 @source = data[:source] data_dir = @source ? File.dirname(@source) : map.data_dir data = map.load_tileset(@source) if @source @name = data[:name] @tile_width = data[:tilewidth] || map.tile_width @tile_height = data[:tileheight] || map.tile_height @spacing = data[:spacing] || 0 @margin = data[:margin] || 0 @tile_count = data[:tilecount] @columns = data[:columns] @tile_offset = data[:tileoffset] || { x: 0, y: 0 } @properties = data[:properties] || {} @tiles = [] tile_images = [] if data[:image] image = map.load_image(data[:image], data[:transparentcolor], data_dir) image_width = data[:imagewidth] || image.width image_height = data[:imageheight] || image.height tile_images = split_image(image, image_width, image_height) image.dispose() else data[:tiles].each_pair do |key, value| tile_images[key.to_s.to_i] = map.load_image(value[:image], nil, data_dir) end end @tile_count = tile_images.size unless @tile_count adjusted_offset_x = map.orientation == IsometricLayer ? map.tile_width / 2 : 0 adjusted_offset_y = @tile_offset[:y] + map.tile_height tile_images.each_with_index do |image, i| next unless image @tiles[i] = Tile.new( image, @tile_offset[:x] - adjusted_offset_x, @tile_offset[:y], adjusted_offset_y - image.height, self ) end tiles_data = data[:tiles] || {} set_types(tiles_data) set_animations(tiles_data) set_collisions(tiles_data) end |
Instance Attribute Details
#animations ⇒ Object (readonly)
Returns the value of attribute animations.
4 5 6 |
# File 'lib/dxruby_tiled/tileset.rb', line 4 def animations @animations end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
4 5 6 |
# File 'lib/dxruby_tiled/tileset.rb', line 4 def columns @columns end |
#firstgid ⇒ Object (readonly)
Returns the value of attribute firstgid.
4 5 6 |
# File 'lib/dxruby_tiled/tileset.rb', line 4 def firstgid @firstgid end |
#margin ⇒ Object (readonly)
Returns the value of attribute margin.
4 5 6 |
# File 'lib/dxruby_tiled/tileset.rb', line 4 def margin @margin end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/dxruby_tiled/tileset.rb', line 4 def name @name end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
4 5 6 |
# File 'lib/dxruby_tiled/tileset.rb', line 4 def properties @properties end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
4 5 6 |
# File 'lib/dxruby_tiled/tileset.rb', line 4 def source @source end |
#spacing ⇒ Object (readonly)
Returns the value of attribute spacing.
4 5 6 |
# File 'lib/dxruby_tiled/tileset.rb', line 4 def spacing @spacing end |
#tile_count ⇒ Object (readonly)
Returns the value of attribute tile_count.
4 5 6 |
# File 'lib/dxruby_tiled/tileset.rb', line 4 def tile_count @tile_count end |
#tile_height ⇒ Object (readonly)
Returns the value of attribute tile_height.
4 5 6 |
# File 'lib/dxruby_tiled/tileset.rb', line 4 def tile_height @tile_height end |
#tile_offset ⇒ Object (readonly)
Returns the value of attribute tile_offset.
4 5 6 |
# File 'lib/dxruby_tiled/tileset.rb', line 4 def tile_offset @tile_offset end |
#tile_width ⇒ Object (readonly)
Returns the value of attribute tile_width.
4 5 6 |
# File 'lib/dxruby_tiled/tileset.rb', line 4 def tile_width @tile_width end |
#tiles ⇒ Object (readonly)
Returns the value of attribute tiles.
4 5 6 |
# File 'lib/dxruby_tiled/tileset.rb', line 4 def tiles @tiles end |
Instance Method Details
#delayed_dispose ⇒ Object
63 64 65 66 67 |
# File 'lib/dxruby_tiled/tileset.rb', line 63 def delayed_dispose() @tiles.each_value do |tile| @tile.image.delayed_dispose() end end |
#dispose ⇒ Object
57 58 59 60 61 |
# File 'lib/dxruby_tiled/tileset.rb', line 57 def dispose() @tiles.each_value do |tile| @tile.image.dispose() end end |
#disposed? ⇒ Boolean
69 70 71 |
# File 'lib/dxruby_tiled/tileset.rb', line 69 def disposed?() @tiles[0].image.disposed?() end |