Class: DxrbTmx
- Inherits:
-
Object
- Object
- DxrbTmx
- Defined in:
- dxrbtmx.rb
Overview
Instance Attribute Summary (collapse)
-
- (int) height
readonly
BGマップの縦幅タイル個数.
-
- (hash) layers_name
readonly
レイヤー名のハッシュ.
-
- (int) map_height
readonly
BGマップの縦ドット数.
-
- (int) map_width
readonly
BGマップの横ドット数.
-
- (Array) mapdata
readonly
全レイヤーのマップデータ(三次元配列).
-
- (int) screenheight
readonly
画面を占める縦幅タイル個数.
-
- (int) screenwidth
readonly
画面を占める横幅タイル個数.
-
- (int) tileheight
readonly
タイルの縦ドット数.
-
- (int) tilewidth
readonly
タイルの横ドット数.
-
- (Object) tmx
tmxライブラリで読み込んだ .tmx オブジェクト.
-
- (int) width
readonly
BGマップの横幅タイル個数.
Instance Method Summary (collapse)
-
- (Object) dump_layers_info
動作確認用。全レイヤー(タイルレイヤー)の情報をダンプする.
-
- (Object) dump_map_size
動作確認用。マップサイズとタイルサイズをダンプする.
-
- (Object) dump_object_group_info
動作確認用。オブジェクトレイヤー情報をダンプする.
-
- (Array) get_layer(layer_name)
レイヤー名を指定して、マップデータ(二次元配列)を得る.
-
- (int) get_layers_length
全レイヤー枚数を返す.
-
- (Object) init_map(tmxfile, scrw, scrh)
マップの初期化.
-
- (DxrbTmx) initialize(tmxfile, scrw, scrh)
constructor
コンストラクタ.
Constructor Details
- (DxrbTmx) initialize(tmxfile, scrw, scrh)
コンストラクタ
59 60 61 |
# File 'dxrbtmx.rb', line 59 def initialize(tmxfile, scrw, scrh) init_map(tmxfile, scrw, scrh) end |
Instance Attribute Details
- (int) height (readonly)
Returns BGマップの縦幅タイル個数
32 33 34 |
# File 'dxrbtmx.rb', line 32 def height @height end |
- (hash) layers_name (readonly)
Returns レイヤー名のハッシュ
26 27 28 |
# File 'dxrbtmx.rb', line 26 def layers_name @layers_name end |
- (int) map_height (readonly)
Returns BGマップの縦ドット数
44 45 46 |
# File 'dxrbtmx.rb', line 44 def map_height @map_height end |
- (int) map_width (readonly)
Returns BGマップの横ドット数
41 42 43 |
# File 'dxrbtmx.rb', line 41 def map_width @map_width end |
- (Array) mapdata (readonly)
Returns 全レイヤーのマップデータ(三次元配列)
23 24 25 |
# File 'dxrbtmx.rb', line 23 def mapdata @mapdata end |
- (int) screenheight (readonly)
Returns 画面を占める縦幅タイル個数
50 51 52 |
# File 'dxrbtmx.rb', line 50 def screenheight @screenheight end |
- (int) screenwidth (readonly)
Returns 画面を占める横幅タイル個数
47 48 49 |
# File 'dxrbtmx.rb', line 47 def screenwidth @screenwidth end |
- (int) tileheight (readonly)
Returns タイルの縦ドット数
38 39 40 |
# File 'dxrbtmx.rb', line 38 def tileheight @tileheight end |
- (int) tilewidth (readonly)
Returns タイルの横ドット数
35 36 37 |
# File 'dxrbtmx.rb', line 35 def tilewidth @tilewidth end |
- (Object) tmx
tmxライブラリで読み込んだ .tmx オブジェクト
20 21 22 |
# File 'dxrbtmx.rb', line 20 def tmx @tmx end |
- (int) width (readonly)
Returns BGマップの横幅タイル個数
29 30 31 |
# File 'dxrbtmx.rb', line 29 def width @width end |
Instance Method Details
- (Object) dump_layers_info
動作確認用。全レイヤー(タイルレイヤー)の情報をダンプする
155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'dxrbtmx.rb', line 155 def dump_layers_info puts "# all layer info" @tmx.layers.each do |layer| name = layer.name # C[ w = layer.width # C[TCY h = layer.height ltype = layer.type # C[ data = layer.data # C[̃}bve[u puts "name: #{name} , #{w} x #{h} , type: #{ltype} , Data length: #{data.length}" end puts "# end" end |
- (Object) dump_map_size
動作確認用。マップサイズとタイルサイズをダンプする
144 145 146 147 148 149 150 |
# File 'dxrbtmx.rb', line 144 def dump_map_size puts "# tmx size" puts "map size = #{self.width} x #{self.height}" puts "tile size = #{self.tilewidth} x #{self.tileheight}" puts "layer length = #{self.get_layers_length}" puts "# end" end |
- (Object) dump_object_group_info
動作確認用。オブジェクトレイヤー情報をダンプする
171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'dxrbtmx.rb', line 171 def dump_object_group_info puts "# object layer info" @tmx.object_groups.each do |objg| puts "object layer name : #{objg.name}" objg.objects.each do |o| name = o.name x = o.x y = o.y puts "#{name} , (#{x},#{y})" end end puts "# end" end |
- (Array) get_layer(layer_name)
レイヤー名を指定して、マップデータ(二次元配列)を得る
128 129 130 |
# File 'dxrbtmx.rb', line 128 def get_layer(layer_name) return @mapdata[@layers_name[layer_name]] end |
- (int) get_layers_length
全レイヤー枚数を返す
137 138 139 |
# File 'dxrbtmx.rb', line 137 def get_layers_length return @tmx.layers.length end |
- (Object) init_map(tmxfile, scrw, scrh)
マップの初期化
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'dxrbtmx.rb', line 70 def init_map(tmxfile, scrw, scrh) @tmx = Tmx.load(tmxfile) # }bv̏c^CL^ @width = @tmx.width @height = @tmx.height # ^C̃hbgTCYL^ @tilewidth = @tmx.tilewidth @tileheight = @tmx.tileheight # }bṽTCY(hbg) L^ @map_width = @width * @tilewidth @map_height = @height * @tileheight @screenwidth = (scrw.to_f / @tilewidth).ceil @screenheight = (scrh.to_f / @tileheight).ceil # }bvpz @mapdata = [] # C[ƃC[ԍ̑Ή @layers_name = {} # SC[̃}bvf[^ɌĂ layernum = 0 @tmx.layers.each do |layer| name = layer.name # C[ w = layer.width # C[TCY(^C) h = layer.height ltype = layer.type # C[ @layers_name[name] = layernum maps = [] i = 0 @height.times do |my| lines = [] @width.times do |mx| n = layer.data[i] # tmx0Ԃ̂ŃR[hԍ lines.push((n <= 0)? 0 : n - 1) i += 1 end maps.push(lines) end @mapdata.push(maps) layernum += 1 end end |