Project1

标题: 游戏的动态模糊效果 [打印本页]

作者: shoed    时间: 2011-8-27 17:27
标题: 游戏的动态模糊效果
本帖最后由 shoed 于 2011-8-28 00:04 编辑

动态模糊效果,我想大家应该都见识过,比如极品飞车游戏中常常会看到这种效果


这么好的效果我们不能用不是太可惜了,经过几天的努力,终于做出了这个效果,我现
在将脚本和工程都发上来,以供参考

先上图:




脚本:
  1. #--------------------------------------------------------------------------
  2. # ● 动态糊模效果
  3. # 制作者  小飞侠_shoed
  4. # 用法:
  5. # 打开
  6. # 开关[模糊效果]=ON
  7. # 开关[模糊效果]=OFF

  8. $模糊效果 = 1
  9. #==============================================================================
  10. # ■ Scene_Map
  11. #==============================================================================
  12. class Scene_Map
  13.   #--------------------------------------------------------------------------
  14.   # ● 主处理
  15.   #--------------------------------------------------------------------------
  16.   alias plan_map_window_main main
  17.   def main
  18.     @blur_window = Blur_Effect.new
  19.     @blur_window.visible=$game_switches[$模糊效果]
  20.     plan_map_window_main
  21.     @blur_window.dispose
  22.   end
  23.   #--------------------------------------------------------------------------
  24.   # ● 更新
  25.   #--------------------------------------------------------------------------
  26.   alias plan_map_window_update update
  27.   def update
  28.     plan_map_window_update
  29.     @blur_window.visible=$game_switches[$模糊效果]
  30.     @blur_window.update
  31.   end
  32.   #--------------------------------------------------------------------------
  33.   # ● 场所移动的变化
  34.   #--------------------------------------------------------------------------
  35.   alias plan_map_window_transfer_player transfer_player
  36.   def transfer_player
  37.     visible = $game_switches[$模糊效果]
  38.     $game_switches[$模糊效果] = false
  39.     @blur_window.visible=$game_switches[$模糊效果]
  40.     plan_map_window_transfer_player
  41.     @blur_window.dispose
  42.     @blur_window = Blur_Effect.new
  43.     $game_switches[$模糊效果] = visible
  44.     @blur_window.visible=$game_switches[$模糊效果]
  45.   end
  46. end

  47. #==============================================================================
  48. # Blur_Effect
  49. #==============================================================================
  50. class Blur_Effect
  51.   def initialize
  52.     @blurSprite=Sprite.new
  53.     @sum=Bitmap.new(640,480)
  54.     @RT=Picture_Map.new
  55.     @blurSprite.bitmap=@sum
  56.     @blurSprite.z=9999
  57.   end
  58.   
  59.   def update
  60.     if $game_switches[$模糊效果] == true
  61.       @RT.update
  62.       @sum.blt(0,0,@RT,Rect.new(0,0,@RT.width,@RT.height),60)
  63.     end
  64.   end
  65.   
  66.   def dispose
  67.     @sum.dispose
  68.     @RT.dispose
  69.     @blurSprite.dispose
  70.   end
  71.   
  72.   def visible=(flag)
  73.     @blurSprite.visible=flag
  74.   end
  75. end

  76. #==============================================================================
  77. # Picture_Character
  78. #==============================================================================
  79. class Picture_Character < Bitmap
  80.   attr_accessor :character                # 角色
  81.   
  82.   def initialize(character = nil)
  83.     @character = character
  84.    
  85.     @bitmap = RPG::Cache.character(@character.character_name,
  86.       @character.character_hue)
  87.     @cw = @bitmap.width / 4
  88.     @ch = @bitmap.height / 4
  89.   
  90.     super(@cw,@ch)
  91.    
  92.     @stopTitles=[]
  93.     @moveTitles=[]
  94.   end
  95.   
  96.   def update
  97.     self.clear
  98.     # 元件 ID、文件名、色相与现在的情况存在差异的情况下
  99.     if @tile_id != @character.tile_id or
  100.        @character_name != @character.character_name or
  101.        @character_hue != @character.character_hue
  102.       # 记忆元件 ID 与文件名、色相
  103.       @tile_id = @character.tile_id
  104.       @character_name = @character.character_name
  105.       @character_hue = @character.character_hue
  106.       # 元件 ID 为有效值的情况下
  107.       if @tile_id >= 384
  108.         @bitmap = RPG::Cache.tile($game_map.tileset_name,
  109.           @tile_id, @character.character_hue)
  110.         @cw = 32
  111.         @ch = 32
  112.       else
  113.         @bitmap = RPG::Cache.character(@character.character_name,
  114.           @character.character_hue)
  115.       end
  116.     end

  117.     # 图形是角色的情况下
  118.     if @tile_id == 0
  119.       # 设置传送目标的矩形
  120.       sx = @character.pattern * @cw
  121.       sy = (@character.direction - 2) / 2 * @ch
  122.       self.blt(0,0,@bitmap,Rect.new(sx,sy,@cw,@ch))
  123.     end
  124.    
  125.     #计算title
  126.     if self.visible
  127.       if @x != self.x or @y != self.y
  128.         @x=self.x
  129.         @y=self.y
  130.         
  131.         @stopTitles.clear
  132.         #@moveTitles.clear
  133.         
  134.         tile_x=self.real_width/32
  135.         if tile_x%2==0
  136.           tile_x+=1
  137.         end
  138.         tile_y=(self.real_height/32.0).ceil
  139.         for j in 0...tile_y
  140.           maskId=[self.x,self.y-j,j]
  141.           @stopTitles.push(maskId)
  142.           for i in 1..(tile_x-1)/2
  143.             maskId=[self.x-i,self.y-j,j]
  144.             @stopTitles.push(maskId)
  145.             maskId=[self.x+i,self.y-j,j]
  146.             @stopTitles.push(maskId)
  147.           end
  148.         end
  149.         
  150.         @[email protected]
  151.         
  152.         case @character.direction
  153.           when 2 #向下
  154.             maskId=[self.x,self.y-tile_y,tile_y]
  155.             @moveTitles.push(maskId)
  156.             for i in 1..(tile_x-1)/2
  157.               maskId=[self.x-i,self.y-tile_y,tile_y]
  158.               @moveTitles.push(maskId)
  159.               maskId=[self.x+i,self.y-tile_y,tile_y]
  160.               @moveTitles.push(maskId)
  161.             end
  162.           when 4 #向左
  163.             for j in 0...tile_y
  164.               maskId=[self.x+(tile_x-1)/2+1,self.y-j,j]
  165.               @moveTitles.push(maskId)
  166.             end
  167.           when 6 #向右
  168.             for j in 0...tile_y
  169.               maskId=[self.x-(tile_x-1)/2-1,self.y-j,j]
  170.               @moveTitles.push(maskId)
  171.             end
  172.           when 8 #向上
  173.             for k in @moveTitles
  174.               k[2]+=1
  175.             end
  176.             maskId=[self.x,self.y+1,0]
  177.             @moveTitles.push(maskId)
  178.             for i in 1..(tile_x-1)/2
  179.               maskId=[self.x-i,self.y+1,0]
  180.               @moveTitles.push(maskId)
  181.               maskId=[self.x+i,self.y+1,0]
  182.               @moveTitles.push(maskId)
  183.             end
  184.           end
  185.       end
  186.     end
  187.   end
  188.   
  189.   def x
  190.     return @character.x
  191.   end
  192.   
  193.   def y
  194.     return @character.y
  195.   end
  196.    
  197.   def screen_x
  198.     return @character.screen_x
  199.   end
  200.   
  201.   def screen_y
  202.     return @character.screen_y
  203.   end
  204.   
  205.   def screen_z
  206.     return @character.screen_z(@ch)
  207.   end
  208.   
  209.   def real_width
  210.     return @cw
  211.   end
  212.   
  213.   def real_height
  214.     return @ch
  215.   end
  216.   
  217.   def visible
  218.     return [email protected]
  219.   end
  220.   
  221.   def opacity
  222.     return @character.opacity
  223.   end
  224.   
  225.   def maskTitles
  226.     if @character.moving?
  227.       return @moveTitles
  228.     else
  229.       return @stopTitles
  230.     end
  231.   end
  232. end


  233. #==============================================================================
  234. # Picture_Map
  235. #==============================================================================
  236. class Picture_Map < Bitmap
  237.   def initialize
  238.     super(640,480)
  239.     @map_cw = $game_map.width * 32
  240.     @map_ch = $game_map.height * 32
  241.    
  242.     @tileset = RPG::Cache.tileset($game_map.tileset_name)
  243.     @autotiles = []
  244.     for i in 0..6
  245.       autotile_name = $game_map.autotile_names[i]
  246.       @autotiles[i] = RPG::Cache.autotile(autotile_name)
  247.     end
  248.     @map_data = $game_map.data
  249.     @priorities = $game_map.priorities
  250.     @character_sprites = []
  251.     for i in $game_map.events.keys.sort
  252.       sprite = Picture_Character.new($game_map.events[i])
  253.       @character_sprites.push(sprite)
  254.     end
  255.     @character_sprites.push(Picture_Character.new($game_player))
  256.     @all_map = Bitmap.new (@map_cw,@map_ch)
  257.     make_map
  258.   end
  259.   
  260.   def update
  261.     self.clear

  262.     self.blt(0,0,@all_map,Rect.new(map_x,map_y,width,height))
  263.    
  264.     # 刷新角色活动块
  265.     @character_sprites.sort!{|a,b|a.screen_z<=>b.screen_z}
  266.     for sprite in @character_sprites
  267.       if sprite.visible
  268.         sprite.update
  269.         
  270.         px=sprite.screen_x-sprite.real_width/2
  271.         py=sprite.screen_y-sprite.real_height
  272.         self.blt(px,py,sprite,Rect.new(0,0,sprite.real_width,sprite.real_height),sprite.opacity)
  273.         
  274.         for mask_id in sprite.maskTitles
  275.           next unless $game_map.valid?(mask_id[0], mask_id[1])
  276.           for i in [2, 1, 0]
  277.             tile = @map_data[mask_id[0], mask_id[1], i]
  278.             next if tile == 0 #透明的
  279.             if $game_map.priorities[tile] > mask_id[2]
  280.               if tile < 384
  281.                 if tile >= 48
  282.                   tile -= 48
  283.                   src_rect = Rect.new(32, 2 * 32, 32, 32)
  284.                   self.blt(mask_id[0] * 32 - map_x, mask_id[1] * 32 - map_y, @autotiles[tile / 48], src_rect)
  285.                 end
  286.               else
  287.                 tile -= 384
  288.                 src_rect = Rect.new(tile % 8 * 32, tile / 8 * 32, 32, 32)
  289.                 self.blt(mask_id[0] * 32 - map_x, mask_id[1] * 32 -  map_y, @tileset, src_rect)
  290.               end
  291.               
  292.               break
  293.             end
  294.           end
  295.         end
  296.       end
  297.     end
  298.   end
  299.   
  300.   def dispose
  301.     super
  302.     # 释放元件地图
  303.     @tileset.dispose
  304.     for i in 0..6
  305.       @autotiles[i].dispose
  306.     end
  307.     # 释放角色活动块
  308.     for sprite in @character_sprites
  309.       sprite.dispose
  310.     end
  311.     @all_map.dispose
  312.    
  313.   end
  314.   
  315.   def make_map
  316.     for y in 0...$game_map.height
  317.       for x in 0...$game_map.width
  318.         for z in 0...3
  319.           tile = @map_data[x, y, z]
  320.           next if tile == nil
  321.           if tile < 384
  322.             if tile >= 48
  323.               tile -= 48
  324.               src_rect = Rect.new(32, 2 * 32, 32, 32)
  325.               @all_map.blt(x * 32, y * 32, @autotiles[tile / 48], src_rect)
  326.             end
  327.           else
  328.             tile -= 384
  329.             src_rect = Rect.new(tile % 8 * 32, tile / 8 * 32, 32, 32)
  330.             @all_map.blt(x * 32, y * 32, @tileset, src_rect)
  331.           end
  332.         end
  333.       end
  334.     end
  335.   end
  336.   
  337.   def map_width
  338.     return @map_cw
  339.   end
  340.   
  341.   def map_height
  342.     return @map_ch
  343.   end

  344.   def map_x
  345.     return $game_map.display_x / 4
  346.   end
  347.   
  348.   def map_y
  349.     return $game_map.display_y / 4
  350.   end
  351. end
复制代码
附件:
动态模糊.rar (229.99 KB, 下载次数: 1706)

用法:
开关[模糊效果]=ON
开关[模糊效果]=OFF



作者: zphyp120    时间: 2011-8-27 17:43
好东西,抱走了。
(为什么我5积分了还不能评分。。)
作者: gghg1989    时间: 2011-8-27 18:21
提示: 作者被禁止或删除 内容自动屏蔽
作者: 颗粒丝丁    时间: 2011-8-27 18:50
挺好的~期待更多地图效果
作者: 编程白痴    时间: 2011-8-27 19:02
好强大的东西,拿走了
作者: 残风水月    时间: 2011-8-27 19:41
看上去效果很好!
作者: 超越时空    时间: 2011-8-27 21:53
这个效果很不错!
作者: 越前リョーマ    时间: 2011-8-30 12:31
这个只适合第一视角游戏吧……RM的这个视角看起来各种违和 = =
作者: 忧雪の伤    时间: 2011-8-30 16:20
  1. 9999.times { $模糊效果 = nil }
复制代码

作者: yangff    时间: 2011-8-30 22:31
这不是残影么……
作者: summer92    时间: 2011-8-30 22:35
不错的样子~~~~~~~~
作者: ZAndiH    时间: 2011-8-31 00:50
用在切换玩家的时候,例如按下某个键切换为二号角色;适用于两主角分开行动时,自由切换,二人配合完成剧情- -

或者回忆?时光倒流?总之好东西啦~
作者: 藏书妹    时间: 2011-8-31 11:36
提示: 作者被禁止或删除 内容自动屏蔽
作者: 不会脚本    时间: 2011-8-31 12:59
我,鼎,这个是好东东啊啊!
作者: 魏玉龙    时间: 2011-9-4 10:42
能不能不要背景模糊 只人物有残影
作者: 7408    时间: 2013-7-9 10:22
BUG?突然发现这个效果打开时,自动元件会出问题....
作者: 346696125    时间: 2013-8-15 08:49
超好用,可以在游戏里做轻功效果{:2_284:}
作者: 东野青龙    时间: 2013-8-15 10:49
我勒个去!真特么绚!
作者: 纯子    时间: 2013-8-15 13:20
看了我肾亏。。。。。。。。




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