Project1

标题: [10VIP悬赏]有人知道Tilemap这个类是怎么定义的吗? [打印本页]

作者: 黑暗之神    时间: 2007-8-2 07:27
标题: [10VIP悬赏]有人知道Tilemap这个类是怎么定义的吗?
如题,想修改点东西,需要知道class Tilemap 这段RM内部的代码…谢了!
另外,如果知道如何查看RMXP的内部类也麻烦告诉我,很多东西要改动的,
十分感谢的说~!
[10VIP悬赏].......不够的话20也行~~~
作者: 黑暗之神    时间: 2007-8-2 07:27
标题: [10VIP悬赏]有人知道Tilemap这个类是怎么定义的吗?
如题,想修改点东西,需要知道class Tilemap 这段RM内部的代码…谢了!
另外,如果知道如何查看RMXP的内部类也麻烦告诉我,很多东西要改动的,
十分感谢的说~!
[10VIP悬赏].......不够的话20也行~~~
作者: 精灵使者    时间: 2007-8-2 08:38
这个建议转向援手区。恩恩。
作者: 亿万星辰    时间: 2007-8-2 14:11
这个东西本身没有提供,现在无非就是自己重新写一个或者想办法继续破解看能不能找着本来的方法........  -v-
作者: 黑暗之神    时间: 2007-8-2 15:13
....就是破解不了,而且没头绪写...
郁闷中…把人物显示的间隔放大了,地图不跟着放大,就错位了,设置通行就麻烦了…

作者: K’    时间: 2007-8-2 17:50
偶这有个以前找到的一个外国人写的 tilemap

可以自定义自动元件的播放速度 也许还有其他功能 米仔细看就丢一边了 刚翻出来。。

也许楼主可以参考下。

  1. #==============================================================================
  2. # ** Game_Map
  3. #==============================================================================

  4. class Game_Map
  5.   #--------------------------------------------------------------------------
  6.   # * Public Instance Variables
  7.   #--------------------------------------------------------------------------
  8.   attr_reader :map
  9.   attr_accessor :tilemap_tone
  10.   attr_accessor :tilemap_plane
  11.   attr_accessor :tilemap_zoom_x
  12.   attr_accessor :tilemap_zoom_y
  13.   attr_accessor :tilemap_tile_width
  14.   attr_accessor :tilemap_tile_height
  15.   #--------------------------------------------------------------------------
  16.   # * Alias Listings
  17.   #--------------------------------------------------------------------------
  18.   alias seph_tilemap_gmap_init initialize
  19.   #--------------------------------------------------------------------------
  20.   # * Object Initialization
  21.   #--------------------------------------------------------------------------
  22.   def initialize
  23.     # Original Initialization
  24.     seph_tilemap_gmap_init
  25.     # Sets Special Tilemap Properties
  26.     @tilemap_tone        = nil
  27.     @tilemap_plane       = false
  28.     @tilemap_zoom_x      = 1.0
  29.     @tilemap_zoom_y      = 1.0
  30.     @tilemap_tile_width  = 32
  31.     @tilemap_tile_height = 32
  32.   end
  33. end

  34. #==============================================================================
  35. # ** Tilemap
  36. #==============================================================================

  37. class Tilemap
  38.   #--------------------------------------------------------------------------
  39.   # * Animated Autotiles Frames Reset
  40.   #--------------------------------------------------------------------------
  41.   Animated_Autotiles_Frames = 15
  42.   #--------------------------------------------------------------------------
  43.   # * Auto-Tiles
  44.   #
  45.   #   Auto-Tile 48 : First Auto-Tile, Constructed of tiles 27, 28, 33, 34
  46.   #--------------------------------------------------------------------------
  47.   Autotiles = [
  48.     [ [27, 28, 33, 34], [ 5, 28, 33, 34], [27,  6, 33, 34], [ 5,  6, 33, 34],
  49.       [27, 28, 33, 12], [ 5, 28, 33, 12], [27,  6, 33, 12], [ 5,  6, 33, 12] ],
  50.     [ [27, 28, 11, 34], [ 5, 28, 11, 34], [27,  6, 11, 34], [ 5,  6, 11, 34],
  51.       [27, 28, 11, 12], [ 5, 28, 11, 12], [27,  6, 11, 12], [ 5,  6, 11, 12] ],
  52.     [ [25, 26, 31, 32], [25,  6, 31, 32], [25, 26, 31, 12], [25,  6, 31, 12],
  53.       [15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12] ],
  54.     [ [29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
  55.       [39, 40, 45, 46], [ 5, 40, 45, 46], [39,  6, 45, 46], [ 5,  6, 45, 46] ],
  56.     [ [25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
  57.       [17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48] ],
  58.     [ [37, 38, 43, 44], [37,  6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
  59.       [37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1,  2,  7,  8] ]
  60.   ]
  61.   #--------------------------------------------------------------------------
  62.   # * Public Instance Variables
  63.   #--------------------------------------------------------------------------
  64.   attr_reader :layers
  65.   attr_accessor :tileset
  66.   attr_accessor :autotiles
  67.   attr_accessor :map_data
  68.   attr_accessor :flash_data
  69.   attr_accessor :priorities
  70.   attr_accessor :visible
  71.   attr_accessor :ox
  72.   attr_accessor :oy
  73.   #--------------------------------------------------------------------------
  74.   # * Object Initialization
  75.   #--------------------------------------------------------------------------
  76.   def initialize(viewport, map = $game_map.map)
  77.     # Creates layers
  78.     @layers = []
  79.     for l in 0...3
  80.       layer = ($game_map.tilemap_plane ?
  81.                Plane.new(viewport) : Sprite.new(viewport))
  82.       layer.bitmap = Bitmap.new(map.width * 32, map.height * 32)
  83.       layer.z = l * 150
  84.       layer.zoom_x = $game_map.tilemap_zoom_x
  85.       layer.zoom_y = $game_map.tilemap_zoom_y
  86.       if (tone = $game_map.tilemap_tone).is_a?(Tone)
  87.         layer.tone = tone
  88.       end
  89.       @layers << layer
  90.     end
  91.     # Sets Tileset Data
  92.     @tileset    = nil  # Refers to Map Tileset Name
  93.     @autotiles  = []   # Refers to Tileset Auto-Tiles (Actual Auto-Tiles)
  94.     @map_data   = nil  # Refers to 3D Array Of Tile Settings
  95.     @flash_data = nil  # Refers to 3D Array of Tile Flashdata
  96.     @priorities = nil  # Refers to Tileset Priorities
  97.     @visible    = true # Refers to Tilest Visibleness
  98.     @ox         = 0    # Bitmap Offsets         
  99.     @oy         = 0    # bitmap Offsets
  100.     @data       = nil  # Acts As Refresh Flag
  101.     # Sets Specials Tile Properties
  102.     @map         = map
  103.     @tone        = $game_map.tilemap_tone
  104.     @plane       = $game_map.tilemap_plane
  105.     @zoom_x      = $game_map.tilemap_zoom_x
  106.     @zoom_y      = $game_map.tilemap_zoom_y
  107.     @tile_width  = $game_map.tilemap_tile_width
  108.     @tile_height = $game_map.tilemap_tile_height
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # * Dispose
  112.   #--------------------------------------------------------------------------
  113.   def dispose
  114.     # Dispose Layers (Sprites)
  115.     for layer in @layers
  116.       layer.dispose
  117.     end
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # * Frame Update
  121.   #--------------------------------------------------------------------------
  122.   def update
  123.     # If Data Changes
  124.     unless @data == @map_data &&
  125.            @tile_width == $game_map.tilemap_tile_width &&
  126.            @tile_height == $game_map.tilemap_tile_height
  127.       refresh
  128.     end
  129.     # Tone Change
  130.     unless @tone == $game_map.tilemap_tone
  131.       @tone = $game_map.tilemap_tone
  132.       @tone = Tone.new(0, 0, 0, 0) if @tone.nil?
  133.       for layer in @layers
  134.         layer.tone = @tone
  135.         layer.tone = @tone
  136.       end
  137.     end
  138.     # Zoom Change
  139.     unless @zoom_x == $game_map.tilemap_zoom_x
  140.       @zoom_x = $game_map.tilemap_zoom_x
  141.       for layer in @layers
  142.         layer.zoom_x = @zoom_x
  143.         layer.zoom_x = @zoom_x
  144.       end
  145.     end
  146.     unless @zoom_y == $game_map.tilemap_zoom_y
  147.       @zoom_y = $game_map.tilemap_zoom_y
  148.       for layer in @layers
  149.         layer.zoom_y = @zoom_y
  150.         layer.zoom_y = @zoom_y
  151.       end
  152.     end
  153.     # Update layer Position offsets
  154.     for layer in @layers
  155.       layer.ox = @ox
  156.       layer.oy = @oy
  157.     end
  158.     # Animated Autotiles
  159.     if Graphics.frame_count % Animated_Autotiles_Frames == 0
  160.       # Refresh Autotiles
  161.       refresh_autotiles
  162.     end
  163.   end
  164.   #--------------------------------------------------------------------------
  165.   # * Refresh
  166.   #--------------------------------------------------------------------------
  167.   def refresh
  168.     # Saves Map Data
  169.     @data = @map_data
  170.     # Passes Through All Priorities
  171.     for p in 0..5
  172.       # Passes Through Layers
  173.       for z in 0...@map_data.zsize
  174.         # Passes Through X Coordinates
  175.         for x in 0...@map_data.xsize
  176.           # Passes Through Z Coordinates
  177.           for y in 0...@map_data.ysize
  178.             # Collects Tile ID
  179.             id = @map_data[x, y, z]
  180.             # Skip if 0 tile
  181.             next if id == 0
  182.             # Skip If Priority Doesn't Match
  183.             next unless p == @priorities[id]
  184.             # Cap Priority to Layer 3
  185.             p = 2 if p > 2
  186.             # Draw Tile
  187.             id < 384 ? draw_autotile(x, y, p, id) : draw_tile(x, y, p, id)
  188.           end
  189.         end
  190.       end
  191.     end
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # * Refresh Auto-Tiles
  195.   #--------------------------------------------------------------------------
  196.   def refresh_autotiles
  197.     # Auto-Tile Locations
  198.     autotile_locations = Table.new(@map_data.xsize, @map_data.ysize,
  199.       @map_data.zsize)
  200.     # Passes Through All Priorities
  201.     for p in 0..5
  202.       # Passes Through Layers
  203.       for z in 0...@map_data.zsize
  204.         # Passes Through X Coordinates
  205.         for x in 0...@map_data.xsize
  206.           # Passes Through Z Coordinates
  207.           for y in 0...@map_data.ysize
  208.             # Collects Tile ID
  209.             id = @map_data[x, y, z]
  210.             # Skip if 0 tile
  211.             next if id == 0
  212.             # Skip If Priority Doesn't Match
  213.             next unless p == @priorities[id]
  214.             # Skip If Non-Animated Tile
  215. #            next unless autotile = @autotiles[id / 48 - 1].width / 96 > 1
  216.             # Cap Priority to Layer 3
  217.             p = 2 if p > 2
  218.             # If Autotile
  219.             if id < 384
  220.               # Draw Auto-Tile
  221.               draw_autotile(x, y, p, id)
  222.               # Save Autotile Location
  223.               autotile_locations[x, y, z] = 1
  224.             # If Normal Tile
  225.             else
  226.               # If Autotile Drawn
  227.               if autotile_locations[x, y, z] == 1
  228.                 # Redraw Normal Tile
  229.                 draw_tile(x, y, p, id)
  230.               end
  231.             end
  232.           end
  233.         end
  234.       end
  235.     end
  236.   end
  237.   #--------------------------------------------------------------------------
  238.   # * Draw Tile
  239.   #--------------------------------------------------------------------------
  240.   def draw_tile(x, y, z, id)
  241.     # Figures Tile Rect
  242.     rect = Rect.new((id - 384) % 8 * 32, (id - 384) / 8 * 32, 32, 32)
  243.     # Calculates Tile Coordinates
  244.     x *= @tile_width
  245.     y *= @tile_height
  246.     # If Normal Tile
  247.     if @tile_width == 32 && @tile_height == 32
  248.       @layers[z].bitmap.blt(x, y, @tileset, rect)
  249.     # If Altered Dimensions
  250.     else
  251.       dest_rect = Rect.new(x, y, @tile_width, @tile_height)
  252.       @layers[z].bitmap.stretch_blt(dest_rect, @tileset, rect)
  253.     end
  254.   end
  255.   #--------------------------------------------------------------------------
  256.   # * Draw Auto-Tile
  257.   #--------------------------------------------------------------------------
  258.   def draw_autotile(x, y, z, tile_id)
  259.     # Gets Auto-Tile
  260.     autotile = @autotiles[tile_id / 48 - 1]
  261.     # Reconfigure Tile ID
  262.     tile_id %= 48
  263.     # Creates Bitmap
  264.     bitmap = Bitmap.new(32, 32)
  265.     # Collects Auto-Tile Tile Layout
  266.     tiles = Autotiles[tile_id / 8][tile_id % 8]
  267.     # Animated Tiles
  268.     frames = autotile.width / 96
  269.     # Configures Animation Offset
  270.     anim = (Graphics.frame_count / Animated_Autotiles_Frames) % frames * 96
  271.     # Draws Auto-Tile Rects
  272.     for i in 0...4
  273.       tile_position = tiles[i] - 1
  274.       src_rect = Rect.new(tile_position % 6 * 16 + anim, tile_position / 6 * 16, 16, 16)
  275.       bitmap.blt(i % 2 * 16, i / 2 * 16, autotile, src_rect)
  276.     end
  277.     # Calculates Tile Coordinates
  278.     x *= @tile_width
  279.     y *= @tile_height
  280.     # If Normal Tile
  281.     if @tile_width == 32 && @tile_height == 32
  282.       @layers[z].bitmap.blt(x, y, bitmap, Rect.new(0, 0, 32, 32))
  283.     # If Altered Dimensions
  284.     else
  285.       dest_rect = Rect.new(x, y, @tile_width, @tile_height)
  286.       @layers[z].bitmap.stretch_blt(dest_rect, bitmap, Rect.new(0, 0, 32, 32))
  287.     end
  288.   end
  289.   #--------------------------------------------------------------------------
  290.   # * Collect Bitmap
  291.   #--------------------------------------------------------------------------
  292.   def bitmap
  293.     # Creates New Blank Bitmap
  294.     bitmap = Bitmap.new(@layers[0].bitmap.width, @layers[0].bitmap.height)
  295.     # Passes Through All Layers
  296.     for layer in @layers
  297.       bitmap.blt(0, 0, layer.bitmap,
  298.         Rect.new(0, 0, bitmap.width, bitmap.height))
  299.     end
  300.     # Return Bitmap
  301.     return bitmap
  302.   end
  303. end
复制代码

作者: 柳柳    时间: 2007-8-3 00:15
呵呵,想当年我们研究了半天也还是不能轻松搞定啊。不过测试了一下K’那个,就在地图绘了一棵树,运行,直接就效果不对。看了一下代码,好像原理和真实原理差不太多,不知道什么地方错了。

……想起当年自己尝试这个得到的一个副产品:http://rpg.blue/viewthread.php?tid=30398

原定义方法没有提供,我可以简单描述一下Tileset和Graphics两个怎么工作的:(非标准版,只是我个人的理解)

首先游戏所有画面刷新都是Graphics.update。那么这个update的一帧时间内,到底刷新了什么?

假设一张画好的地图,上面有Tileset,人物,显示的图片,一个人物还在播放魔法。那么:
1、先把所有涉嫌参与显示的素材加载到内存
2、建立一个Z取最小值的画布
3、把所有需要显示的内容,统一获得获得一个Z值。按照Z的从小到大的顺序排列(这里Tileset你可以理解为每一个32×32的小格是独立的Sprite,所以每个小格的Z都不同,这些Z值用数据库图块中优先级和本身的Y坐标确定,用于和人物互动)。
4、按照Z从小到大,从内存找到素材,然后把需要的Rect给strech_blt到画布正确的位置。其中alpha_blend使用普通和加法来计算。strech_blt的算法是从把拉伸后的图片(或者一边计算拉伸一边取颜色)按照1象素1行,切成很多行,循环每个行上每个点。当是普通,直接把这个点的颜色替换画布上对应点颜色,否则就进行一定计算得到画布上新的点的颜色。
5、全部算完替换完,这一帧就算刷新完了。

这是每次输入Graphics.update它会干的事情。这么说是否能大概知道Tileset的计算方法了?
作者: 柳柳    时间: 2007-8-3 01:18
本来想详细写一个Tilemap出来,后来觉得算了,怪麻烦的。我说说大体的算法吧。


def initialize
layer[j] = Sprite, .bitmap = Bitmap.new(640, 32 * 6)  <--6是因为优先级取0-5
j取值-1到16。
layer[j].y = j * 32 (或类似的)
layer[j].z = function get_z(.y) (参考game_character的def screen_z)

def refresh
for map_layer in 1..3  <--循环3层
  for i in -1..21
    for j in -1..16  <--这两个循环地图上所有格以及显示区域边缘以外一圈的格子
      pro = function 获取[i,j]格第map_layer层的优先级
      wahaha_z = function 获取当前这一层这一格在当前屏幕状态下应有的Z值
      按照z,把素材中正确的一格考到layer[某]中的适当位置。这个layer[某].z = wahaha_z

def update
1、Sprite不update原有内容(注意这点,效率的关键问题)
2、update 所有layer的x, y
3、当镜头挪动了1格之后,refresh一次,重新考layer

def dispose



大概就是这样。
[LINE]1,#dddddd[/LINE]系统信息:本贴获得楼主认可,66RPG感谢您的热情解答~
作者: 柳柳    时间: 2007-8-3 06:56
我建议是不要这么改
切格的方法很多的,但是最好不要引入小数……
你可以看我http://rpg.blue/viewthread.php?tid=30398这个,也是修改了格子大小,只是使用的是16×16的格子大小,对你而言只是用48×48而已。
这个方法理论上绝对不卡,因为只是双远景+一层绘制。而且游戏制作方面维持RMXP原样不用任何调整,只是素材方面需要像范例里面那样改改。你可以稍微看看……

当然,也可能是我没理解你说的方法,总之只要有种解决模式就行了
作者: 黑暗之神    时间: 2007-8-3 09:04
恩,因为不想用两张图制作地图(不过也许可以绘制好把绘制用的图删掉的说)…
总之,切格的话是有考虑过,不过既然暂时解决了就先待命了,待开始制作剧情时看看有什么缺点没有,有的话再改了…现,在游戏中暂时没有发现什么不妥的地方…
作者: danny8376    时间: 2007-12-16 08:53
這有個腳本

自己寫的

Ver.1.0

不過FPS會降到15

走路時降到5

之前也有個Ver.0.5的

FPS降到30而已

不過沒在現在這台上

  1. #==============================================================================
  2. # Super Tilemap
  3. # 作者:釣到一隻猴子@_@ ( AAM@_@ )
  4. # 版本:Ver.1.0
  5. # 本資訊不得刪除
  6. #==============================================================================
  7. #==============================================================================
  8. # ■ Tilemap
  9. #------------------------------------------------------------------------------
  10. #  顯示地圖的核心。
  11. #==============================================================================

  12. class Tilemap
  13.   #--------------------------------------------------------------------------
  14.   # ● 定量
  15.   #--------------------------------------------------------------------------
  16.   Animated_Autotiles_Frames = 15
  17.   Scroll_Times = 4
  18.   Autotiles = [
  19.     [ [27, 28, 33, 34], [ 5, 28, 33, 34], [27,  6, 33, 34], [ 5,  6, 33, 34],
  20.       [27, 28, 33, 12], [ 5, 28, 33, 12], [27,  6, 33, 12], [ 5,  6, 33, 12] ],
  21.     [ [27, 28, 11, 34], [ 5, 28, 11, 34], [27,  6, 11, 34], [ 5,  6, 11, 34],
  22.       [27, 28, 11, 12], [ 5, 28, 11, 12], [27,  6, 11, 12], [ 5,  6, 11, 12] ],
  23.     [ [25, 26, 31, 32], [25,  6, 31, 32], [25, 26, 31, 12], [25,  6, 31, 12],
  24.       [15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12] ],
  25.     [ [29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
  26.       [39, 40, 45, 46], [ 5, 40, 45, 46], [39,  6, 45, 46], [ 5,  6, 45, 46] ],
  27.     [ [25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
  28.       [17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48] ],
  29.     [ [37, 38, 43, 44], [37,  6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
  30.       [37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1,  2,  7,  8] ]
  31.   ]
  32.   #--------------------------------------------------------------------------
  33.   # ● 定義外部變數
  34.   #--------------------------------------------------------------------------
  35.   attr_reader :layers
  36.   attr_accessor :tileset
  37.   attr_accessor :autotiles
  38.   attr_accessor :map_data
  39.   attr_accessor :flash_data
  40.   attr_accessor :priorities
  41.   attr_accessor :visible
  42.   attr_accessor :ox
  43.   attr_accessor :oy
  44.   attr_accessor :tone
  45.   attr_accessor :zoom_x
  46.   attr_accessor :zoom_y
  47.   #--------------------------------------------------------------------------
  48.   # ● 初始化
  49.   #--------------------------------------------------------------------------
  50.   def initialize(viewport)
  51.     # 生成圖層
  52.     @layers = []
  53.     for l in 0..5
  54.       layer = Sprite.new(viewport)
  55.       layer.bitmap = Bitmap.new(640, 480)
  56.       layer.z = (l == 0 ? 0 : (64 + 32 * (l - 1)))
  57.       @layers << layer
  58.     end
  59.     # 定義變數
  60.     @tileset    = nil
  61.     @autotiles  = []
  62.     @map_data   = nil
  63.     @flash_data = nil
  64.     @priorities = nil
  65.     @visible    = true
  66.     @ox = @o_ox = 0
  67.     @oy = @o_oy = 0
  68.     @tone       = nil
  69.     @zoom_x     = 1.0
  70.     @zoom_y     = 1.0
  71.   end
  72.   #--------------------------------------------------------------------------
  73.   # ● 釋放
  74.   #--------------------------------------------------------------------------
  75.   def dispose
  76.     # 釋放圖層
  77.     for layer in @layers
  78.       layer.dispose
  79.     end
  80.   end
  81.   #--------------------------------------------------------------------------
  82.   # ● 更新
  83.   #--------------------------------------------------------------------------
  84.   def update
  85.     # 地圖資訊更換
  86.     if @o_map_data != @map_data
  87.       @o_map_data = @map_data
  88.       refresh
  89.     end
  90.     # 偏移座標更換
  91.     if @o_ox != @ox or @o_oy != @oy
  92.       sx = @ox - @o_ox
  93.       sy = @oy - @o_oy
  94.       @o_ox = @ox
  95.       @o_oy = @oy
  96.       refresh#_map(sx, sy)
  97.     end
  98.     # 色調更換
  99.     if @o_tone != @tone
  100.       @o_tone = @tone
  101.       @tone = Tone.new(0, 0, 0, 0) if @tone.nil?
  102.       for layer in @layers
  103.         layer.tone = @tone
  104.       end
  105.     end
  106.     # 比例更換
  107.     if @o_zoom_x != @zoom_x
  108.       @o_zoom_x = @zoom_x
  109.       for layer in @layers
  110.         layer.zoom_x = @zoom_x
  111.       end
  112.     end
  113.     if @o_zoom_y != @zoom_y
  114.       @o_zoom_y = @zoom_y
  115.       for layer in @layers
  116.         layer.zoom_y = @zoom_y
  117.       end
  118.     end
  119.     # 自動元件動畫
  120.     if Graphics.frame_count % Animated_Autotiles_Frames == 0
  121.       # 更新自動元件
  122.       refresh_autotiles
  123.     end
  124.   end
  125.   #--------------------------------------------------------------------------
  126.   # ● 更新元件
  127.   #--------------------------------------------------------------------------
  128.   def refresh_map(sx, sy)
  129.     # 圖層捲動
  130.     move(0, sx)
  131.     move(0, sy)
  132.     # 循環所有優先級
  133.     for p in 0..5
  134.       # 循環所有圖層
  135.       for z in 0...@map_data.zsize
  136.         # 循環所有X座標
  137.         for x in 0...20
  138.           # 循環所有Y座標
  139.           for y in 0...15
  140.             # 當偏移座標不正常時略過
  141.             next if @ox < 0
  142.             next if @oy < 0
  143.             # 取得元件ID
  144.             mx = @ox / 32
  145.             my = @oy / 32
  146.             id = @map_data[x + mx, y + my, z]
  147.             # 當元件ID不正常時略過
  148.             next if id == 0
  149.             # 當圖層不符時略過
  150.             next unless p == @priorities[id]
  151.             # 描繪元件(自動元件)
  152.             id < 384 ? draw_autotile(x, y, p, id) : draw_tile(x, y, p, id)
  153.           end
  154.         end
  155.       end
  156.     end
  157.     # 循環所有優先級
  158.     for p in 0..5
  159.       # 循環所有圖層
  160.       for z in 0...@map_data.zsize
  161.         # 循環所有X座標
  162.         for x in 0...20
  163.           # 循環所有Y座標
  164.           for y in 0...15
  165.             # 當偏移座標不正常時略過
  166.             next if @ox < 0
  167.             next if @oy < 0
  168.             # 取得元件ID
  169.             mx = @ox / 32
  170.             my = @oy / 32
  171.             id = @map_data[x + mx, y + my, z]
  172.             # 當元件ID不正常時略過
  173.             next if id == 0
  174.             # 當圖層不符時略過
  175.             next unless p == @priorities[id]
  176.             # 描繪元件(自動元件)
  177.             id < 384 ? draw_autotile(x, y, p, id) : draw_tile(x, y, p, id)
  178.           end
  179.         end
  180.       end
  181.     end
  182.   end
  183.   #--------------------------------------------------------------------------
  184.   # ● 圖層捲動
  185.   #--------------------------------------------------------------------------
  186.   def move(d, v)
  187.     # 設定單次移動距離
  188.     v /= Scroll_Times
  189.     # 循環次數
  190.     for i in 0...Scroll_Times
  191.       # 判斷方向
  192.       case d
  193.       when 0
  194.         # 移動圖層
  195.         for layer in @layers
  196.           bitmap = layer.bitmap
  197.           layer.bitmap.blt(v, 0, bitmap, Rect.new(0, 0, 640, 480))
  198.         end
  199.       when 1
  200.         # 移動圖層
  201.         for layer in @layers
  202.           bitmap = layer.bitmap
  203.           layer.bitmap.blt(0, v, bitmap, Rect.new(0, 0, 640, 480))
  204.         end
  205.       end
  206.     end
  207.   end
  208.   #--------------------------------------------------------------------------
  209.   # ● 初次描繪地圖
  210.   #--------------------------------------------------------------------------
  211.   def refresh
  212.     # 循環所有優先級
  213.     for p in 0..5
  214.       # 循環所有圖層
  215.       for z in 0...@map_data.zsize
  216.         # 循環所有X座標
  217.         for x in 0...20
  218.           # 循環所有Y座標
  219.           for y in 0...15
  220.             # 當偏移座標不正常時略過
  221.             next if @ox < 0
  222.             next if @oy < 0
  223.             # 取得元件ID
  224.             mx = @ox / 32
  225.             my = @oy / 32
  226.             id = @map_data[x + mx, y + my, z]
  227.             # 當元件ID不正常時略過
  228.             next if id == 0
  229.             # 當圖層不符時略過
  230.             next unless p == @priorities[id]
  231.             # 描繪元件(自動元件)
  232.             id < 384 ? draw_autotile(x, y, p, id) : draw_tile(x, y, p, id)
  233.           end
  234.         end
  235.       end
  236.     end
  237.   end
  238.   #--------------------------------------------------------------------------
  239.   # ● 更新自動元件
  240.   #--------------------------------------------------------------------------
  241.   def refresh_autotiles
  242.     # 循環所有優先級
  243.     for p in 0..5
  244.       # 循環所有圖層
  245.       for z in 0...@map_data.zsize
  246.         # 循環所有X座標
  247.         for x in 0...20
  248.           # 循環所有Y座標
  249.           for y in 0...15
  250.             # 當偏移座標不正常時略過
  251.             next if @ox < 0
  252.             next if @oy < 0
  253.             # 取得元件ID
  254.             mx = @ox / 32
  255.             my = @oy / 32
  256.             id = @map_data[x + mx, y + my, z]
  257.             # 當元件ID不正常時略過
  258.             next if id == 0
  259.             # 當圖層不符時略過
  260.             next unless p == @priorities[id]
  261.             # 描繪元件(自動元件)
  262.             draw_autotile(x, y, p, id) if id < 384
  263.           end
  264.         end
  265.       end
  266.     end
  267.   end
  268.   #--------------------------------------------------------------------------
  269.   # ● 描繪元件
  270.   #--------------------------------------------------------------------------
  271.   def draw_tile(x, y, z, id)
  272.     # 設定元件矩形座標範圍
  273.     rect = Rect.new((id - 384) % 8 * 32, (id - 384) / 8 * 32, 32, 32)
  274.     # 假想座標轉為實際座標
  275.     x *= 32
  276.     y *= 32
  277.     # 描繪圖形
  278.     @layers[z].bitmap.blt(x, y, @tileset, rect)
  279.   end
  280.   #--------------------------------------------------------------------------
  281.   # ● 描繪自動元件
  282.   #--------------------------------------------------------------------------
  283.   def draw_autotile(x, y, z, tile_id)
  284.     # 取得自動元件
  285.     autotile = @autotiles[tile_id / 48 - 1]
  286.     # 取得自動元件ID
  287.     tile_id %= 48
  288.     # 生成暫時圖形區塊
  289.     bitmap = Bitmap.new(32, 32)
  290.     # 取得自動元件編號
  291.     tiles = Autotiles[tile_id / 8][tile_id % 8]
  292.     # 自動元件動畫
  293.     frames = autotile.width / 96
  294.     # 設定動畫偏移座標
  295.     anim = (Graphics.frame_count / Animated_Autotiles_Frames) % frames * 96
  296.     # 生成自動元件圖塊
  297.     for i in 0...4
  298.       tile_position = tiles[i] - 1
  299.       src_rect = Rect.new(tile_position % 6 * 16 + anim,
  300.                           tile_position / 6 * 16, 16, 16)
  301.       bitmap.blt(i % 2 * 16, i / 2 * 16, autotile, src_rect)
  302.     end
  303.     # 假想座標轉為實際座標
  304.     x *= 32
  305.     y *= 32
  306.     # 描繪圖形
  307.     @layers[z].bitmap.blt(x, y, bitmap, Rect.new(0, 0, 32, 32))
  308.   end
  309. end
复制代码

作者: 大东    时间: 2009-5-16 23:12
未免也太复杂了!怎么看的懂啊!
作者: tommay    时间: 2009-5-16 23:16
以下引用大东于2009-5-16 15:12:34的发言:

未免也太复杂了!怎么看的懂啊!

挖坟者自重。这些是高手们交流的,新手就算了吧。
作者: 黑暗之神    时间: 2009-6-12 08:00
用了上面的方法,发现不太理想…放大素材的话又卡
只好用我最后的方法:
既然是事件的间隔放大了1.5倍,从原来的128变成了192,画面等也设置成了192,所以这个只是显示的位置,跟他实际的坐标不符合,于是就在初始化时将他们的坐标缩小1.5倍,然后把通行的设置放大1.5倍,这样游戏中通行就没有问题了,并且事件放置的位置也会出现在大概的位置…
只是有一点,因为坐标/1.5的关系实际位置有所出入,设置就麻烦了点…也许临近的两个事件运行后就变成重叠在一起了,设置时要配合运行查看实际的位置效果…
大概目前我的工程只能这样了…设置麻烦了点,不过里面没问题就可以了…

---谢谢柳柳,K’




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1