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.
-
#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_images ⇒ Object
readonly
Returns the value of attribute tile_images.
-
#tile_offset ⇒ Object
readonly
Returns the value of attribute tile_offset.
-
#tile_width ⇒ Object
readonly
Returns the value of attribute tile_width.
Instance Method Summary collapse
-
#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 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dxruby_tiled/tileset.rb', line 8 def initialize(data, map) @data = data @map = map @firstgid = data[:firstgid] || 1 @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] # unsupported @properties = data[:properties] || {} image = @map.load_image(data[:image]) if data[:transparentcolor] color = data[:transparentcolor].sub("#", "").scan(/../).map{|c| c.to_i(16) } image.set_color_key(color) end image_width = data[:imagewidth] || image.width image_height = data[:imageheight] || image.height @tile_images = [] i = 0 col = 1 x = @margin y = @margin loop do if x + @tile_width > image_width || (@columns && col > @columns) x = @margin y += @tile_height + @spacing col = 1 end break if y + @tile_height > image_height @tile_images[i] = image.slice(x, y, @tile_width, @tile_height) x += @tile_width + @spacing i += 1 col += 1 break if @tile_count && i >= @tile_count end @tile_count = i unless @tile_count image.dispose() @animations = {} (data[:tiles] || {}).each_pair do |key, value| next unless value.has_key?(:animation) anim_time = [] anim_image = [] time = 0 value[:animation].each do |anim| anim_time.push(time) anim_image.push(@tile_images[anim[:tileid]]) time += anim[:duration] end anim_time.push(time) @animations[@firstgid + key.to_s.to_i] = { time: anim_time, image: anim_image } end 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 |
#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_images ⇒ Object (readonly)
Returns the value of attribute tile_images.
4 5 6 |
# File 'lib/dxruby_tiled/tileset.rb', line 4 def tile_images @tile_images 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 |