动态模糊效果,我想大家应该都见识过,比如极品飞车游戏中常常会看到这种效果
这么好的效果我们不能用不是太可惜了,经过几天的努力,终于做出了这个效果,我现
在将脚本和工程都发上来,以供参考
先上图:
脚本:
- #--------------------------------------------------------------------------# ● 动态糊模效果# 制作者 小飞侠_shoed# 用法:# 打开# 开关[模糊效果]=ON# 开关[模糊效果]=OFF$模糊效果 = 1#==============================================================================# ■ Scene_Map#==============================================================================class Scene_Map #-------------------------------------------------------------------------- # ● 主处理 #-------------------------------------------------------------------------- alias plan_map_window_main main def main @blur_window = Blur_Effect.new @blur_window.visible=$game_switches[$模糊效果] plan_map_window_main @blur_window.dispose end #-------------------------------------------------------------------------- # ● 更新 #-------------------------------------------------------------------------- alias plan_map_window_update update def update plan_map_window_update @blur_window.visible=$game_switches[$模糊效果] @blur_window.update end #-------------------------------------------------------------------------- # ● 场所移动的变化 #-------------------------------------------------------------------------- alias plan_map_window_transfer_player transfer_player def transfer_player visible = $game_switches[$模糊效果] $game_switches[$模糊效果] = false @blur_window.visible=$game_switches[$模糊效果] plan_map_window_transfer_player @blur_window.dispose @blur_window = Blur_Effect.new $game_switches[$模糊效果] = visible @blur_window.visible=$game_switches[$模糊效果] endend#==============================================================================# Blur_Effect#==============================================================================class Blur_Effect def initialize @blurSprite=Sprite.new @sum=Bitmap.new(640,480) @RT=Picture_Map.new @blurSprite.bitmap=@sum @blurSprite.z=9999 end def update if $game_switches[$模糊效果] == true @RT.update @sum.blt(0,0,@RT,Rect.new(0,0,@RT.width,@RT.height),60) end end def dispose @sum.dispose @RT.dispose @blurSprite.dispose end def visible=(flag) @blurSprite.visible=flag endend#==============================================================================# Picture_Character#==============================================================================class Picture_Character < Bitmap attr_accessor :character # 角色 def initialize(character = nil) @character = character @bitmap = RPG::Cache.character(@character.character_name, @character.character_hue) @cw = @bitmap.width / 4 @ch = @bitmap.height / 4 super(@cw,@ch) @stopTitles=[] @moveTitles=[] end def update self.clear # 元件 ID、文件名、色相与现在的情况存在差异的情况下 if @tile_id != @character.tile_id or @character_name != @character.character_name or @character_hue != @character.character_hue # 记忆元件 ID 与文件名、色相 @tile_id = @character.tile_id @character_name = @character.character_name @character_hue = @character.character_hue # 元件 ID 为有效值的情况下 if @tile_id >= 384 @bitmap = RPG::Cache.tile($game_map.tileset_name, @tile_id, @character.character_hue) @cw = 32 @ch = 32 else @bitmap = RPG::Cache.character(@character.character_name, @character.character_hue) end end # 图形是角色的情况下 if @tile_id == 0 # 设置传送目标的矩形 sx = @character.pattern * @cw sy = (@character.direction - 2) / 2 * @ch self.blt(0,0,@bitmap,Rect.new(sx,sy,@cw,@ch)) end #计算title if self.visible if @x != self.x or @y != self.y @x=self.x @y=self.y @stopTitles.clear #@moveTitles.clear tile_x=self.real_width/32 if tile_x%2==0 tile_x+=1 end tile_y=(self.real_height/32.0).ceil for j in 0...tile_y maskId=[self.x,self.y-j,j] @stopTitles.push(maskId) for i in 1..(tile_x-1)/2 maskId=[self.x-i,self.y-j,j] @stopTitles.push(maskId) maskId=[self.x+i,self.y-j,j] @stopTitles.push(maskId) end end @[email protected] case @character.direction when 2 #向下 maskId=[self.x,self.y-tile_y,tile_y] @moveTitles.push(maskId) for i in 1..(tile_x-1)/2 maskId=[self.x-i,self.y-tile_y,tile_y] @moveTitles.push(maskId) maskId=[self.x+i,self.y-tile_y,tile_y] @moveTitles.push(maskId) end when 4 #向左 for j in 0...tile_y maskId=[self.x+(tile_x-1)/2+1,self.y-j,j] @moveTitles.push(maskId) end when 6 #向右 for j in 0...tile_y maskId=[self.x-(tile_x-1)/2-1,self.y-j,j] @moveTitles.push(maskId) end when 8 #向上 for k in @moveTitles k[2]+=1 end maskId=[self.x,self.y+1,0] @moveTitles.push(maskId) for i in 1..(tile_x-1)/2 maskId=[self.x-i,self.y+1,0] @moveTitles.push(maskId) maskId=[self.x+i,self.y+1,0] @moveTitles.push(maskId) end end end end end def x return @character.x end def y return @character.y end def screen_x return @character.screen_x end def screen_y return @character.screen_y end def screen_z return @character.screen_z(@ch) end def real_width return @cw end def real_height return @ch end def visible return [email protected] end def opacity return @character.opacity end def maskTitles if @character.moving? return @moveTitles else return @stopTitles end endend#==============================================================================# Picture_Map#==============================================================================class Picture_Map < Bitmap def initialize super(640,480) @map_cw = $game_map.width * 32 @map_ch = $game_map.height * 32 @tileset = RPG::Cache.tileset($game_map.tileset_name) @autotiles = [] for i in 0..6 autotile_name = $game_map.autotile_names[i] @autotiles[i] = RPG::Cache.autotile(autotile_name) end @map_data = $game_map.data @priorities = $game_map.priorities @character_sprites = [] for i in $game_map.events.keys.sort sprite = Picture_Character.new($game_map.events[i]) @character_sprites.push(sprite) end @character_sprites.push(Picture_Character.new($game_player)) @all_map = Bitmap.new (@map_cw,@map_ch) make_map end def update self.clear self.blt(0,0,@all_map,Rect.new(map_x,map_y,width,height)) # 刷新角色活动块 @character_sprites.sort!{|a,b|a.screen_zb.screen_z} for sprite in @character_sprites if sprite.visible sprite.update px=sprite.screen_x-sprite.real_width/2 py=sprite.screen_y-sprite.real_height self.blt(px,py,sprite,Rect.new(0,0,sprite.real_width,sprite.real_height),sprite.opacity) for mask_id in sprite.maskTitles next unless $game_map.valid?(mask_id[0], mask_id[1]) for i in [2, 1, 0] tile = @map_data[mask_id[0], mask_id[1], i] next if tile == 0 #透明的 if $game_map.priorities[tile] > mask_id[2] if tile < 384 if tile >= 48 tile -= 48 src_rect = Rect.new(32, 2 * 32, 32, 32) self.blt(mask_id[0] * 32 - map_x, mask_id[1] * 32 - map_y, @autotiles[tile / 48], src_rect) end else tile -= 384 src_rect = Rect.new(tile % 8 * 32, tile / 8 * 32, 32, 32) self.blt(mask_id[0] * 32 - map_x, mask_id[1] * 32 - map_y, @tileset, src_rect) end break end end end end end end def dispose super # 释放元件地图 @tileset.dispose for i in 0..6 @autotiles[i].dispose end # 释放角色活动块 for sprite in @character_sprites sprite.dispose end @all_map.dispose end def make_map for y in 0...$game_map.height for x in 0...$game_map.width for z in 0...3 tile = @map_data[x, y, z] next if tile == nil if tile < 384 if tile >= 48 tile -= 48 src_rect = Rect.new(32, 2 * 32, 32, 32) @all_map.blt(x * 32, y * 32, @autotiles[tile / 48], src_rect) end else tile -= 384 src_rect = Rect.new(tile % 8 * 32, tile / 8 * 32, 32, 32) @all_map.blt(x * 32, y * 32, @tileset, src_rect) end end end end end def map_width return @map_cw end def map_height return @map_ch end def map_x return $game_map.display_x / 4 end def map_y return $game_map.display_y / 4 endend复制代码
复制代码附件:
用法:
开关[模糊效果]=ON
开关[模糊效果]=OFF
本帖来自P1论坛作者shoed,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:
https://rpg.blue/forum.php?mod=viewthread&tid=207413 若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。