RGSS Tips @Wiki

プレイヤーのいるマップを一枚絵にする(タイルのみ)

最終更新:

匿名ユーザー

- view
管理者のみ編集可

オートタイルは、内部でタイルの配置を換えています。(左の画像から右の画像へ)
AUTOTILE_DATA = [26,27, 4,27,26, 5, 4, 5,26,27, 4,27,26, 5, 4, 5,
                 32,33,32,33,32,33,32,33,32,11,32,11,32,11,32,11,
                 26,27, 4,27,26, 5, 4, 5,26,27, 4,27,26, 5, 4, 5,
                 10,33,10,33,10,33,10,33,10,11,10,11,10,11,10,11,
                 24,25,24, 5,24,25,24, 5,14,15,14,15,14,15,14,15,
                 30,31,30,31,30,11,30,11,20,21,20,11,10,21,10,11,
                 28,29,28,29, 4,29, 4,29,38,39, 4,39,38, 5, 4, 5,
                 34,35,10,35,34,35,10,35,44,45,44,45,44,45,44,45,
                 24,29,14,15,12,13,12,13,16,17,16,17,40,41, 4,41,
                 30,35,44,45,18,19,18,11,22,23,10,23,46,47,46,47,
                 36,37,36, 5,12,17,12,13,36,41,16,17,12,17, 0, 1,
                 42,43,42,43,18,23,42,43,42,47,46,47,42,47, 6, 7
                 ]
#--------------------------------------------------------------------------
# ● タイルを展開してまとめる (タイルとオートタイル)
#--------------------------------------------------------------------------
def make_tile
  # タイルを取得
  tileset = RPG::Cache.tileset($game_map.tileset_name)
  autotile_height = 32 * 6 * 8
  bitmap = Bitmap.new(tileset.width, autotile_height + tileset.height)
  src_rect = Rect.new(0, 0, tileset.width, tileset.height)
  bitmap.blt(0, autotile_height, tileset, src_rect)
  # オートタイルを取得
  for i in 0..6
    autotile_name = $game_map.autotile_names[i]
    unless autotile_name.empty?
      autotile = RPG::Cache.autotile(autotile_name)
      for n in 0...AUTOTILE_DATA.size
        id = AUTOTILE_DATA[n]
        x = id % 6 * 16
        y = id / 6 * 16
        src_rect.set(x, y, 16, 16)
        x = n % 16 * 16
        y = (i + 1) * 6 * 32 + n / 16 * 16
        bitmap.blt(x, y, autotile, src_rect)
      end
    end
  end
  return bitmap
end
これで一枚の画像にまとめられたタイルが返ります。
オートタイルは7個ですが空のタイルを最初に入れて8個にしています。(下の tile_data の番号にあわせるため)
上の make_tile で作った画像を下の make_map に渡します。
#--------------------------------------------------------------------------
# ● マップの作成
#--------------------------------------------------------------------------
def make_map(tile_bitmap)
  # 標準サイズで作成
  map_bitmap = Bitmap.new($game_map.width * 32, $game_map.height * 32)
  for y in 0...$game_map.height
    for x in 0...$game_map.width
      for z in 0...3
        tile_data = $game_map.data[x, y, z]
        next if tile_data == nil
        # 空タイルの以外の場合
         unless tile_data < 48
          src_rect = Rect.new(tile_data % 8 * 32, tile_data / 8 * 32, 32, 32)
          map_bitmap.blt(x * 32, y * 32, tile_bitmap, src_rect)
        end
      end
    end
  end
  tile_bitmap.dispose
  tile_bitmap = nil
  return map_bitmap
end
これでマップ画像が返ります。
記事メニュー
人気記事ランキング
目安箱バナー