Class: DXRuby::Tiled::Tileset

Inherits:
Object
  • Object
show all
Defined in:
lib/dxruby_tiled/tileset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#animationsObject (readonly)

Returns the value of attribute animations.



4
5
6
# File 'lib/dxruby_tiled/tileset.rb', line 4

def animations
  @animations
end

#columnsObject (readonly)

Returns the value of attribute columns.



4
5
6
# File 'lib/dxruby_tiled/tileset.rb', line 4

def columns
  @columns
end

#firstgidObject (readonly)

Returns the value of attribute firstgid.



4
5
6
# File 'lib/dxruby_tiled/tileset.rb', line 4

def firstgid
  @firstgid
end

#marginObject (readonly)

Returns the value of attribute margin.



4
5
6
# File 'lib/dxruby_tiled/tileset.rb', line 4

def margin
  @margin
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/dxruby_tiled/tileset.rb', line 4

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



4
5
6
# File 'lib/dxruby_tiled/tileset.rb', line 4

def properties
  @properties
end

#sourceObject (readonly)

Returns the value of attribute source.



4
5
6
# File 'lib/dxruby_tiled/tileset.rb', line 4

def source
  @source
end

#spacingObject (readonly)

Returns the value of attribute spacing.



4
5
6
# File 'lib/dxruby_tiled/tileset.rb', line 4

def spacing
  @spacing
end

#tile_countObject (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_heightObject (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_offsetObject (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_widthObject (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

#tilesObject (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_disposeObject



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

#disposeObject



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

Returns:

  • (Boolean)


69
70
71
# File 'lib/dxruby_tiled/tileset.rb', line 69

def disposed?()
  @tiles[0].image.disposed?()
end