XP Style Fog
XP Style Fog 1.0Shaz
Introduction
This is a simple port of XP's fog system.
Features
- Add fog via map notes or via a Call Script command
- Change fog tone and opacity via a Call Script command
How to Use
Paste script into a new slot below Materials. All methods are aliased, so this can go below other custom scripts.
Add fog to a map via map notes as follows:
Code:
<fog name hue opacity blend_type zoom speed-x speed-y>
or via a Call Script command:
Code:
Call Script: $game_map.add_fog(name, hue, opacity, blend_type, zoom, speed_x, speed_y)
Change fog via a Call Script command:
Code:
Call Script: $game_map.start_fog_tone_change(red, green, blue, gray, duration)Call Script: $game_map.start_fog_opacity_change(opacity, duration)
Script
Spoiler Code:
#============================================================================# XP Style Fog# v1.0 by Shaz#----------------------------------------------------------------------------# This is a simple port of XP's fog system.#----------------------------------------------------------------------------# To Install:# Copy and paste into a new script slot in Materials.This script aliases# existing methods, so can go below all other custom scripts.#----------------------------------------------------------------------------# To Use:# Create a Fogs folder inside your game's Graphics folder, and paste your# fog png files there## There are two ways of adding fog to a map:# 1. Set it in map notes - fog will be loaded when the map is loaded (all values # must be present)# <fog name hue opacity blend_type zoom speed-x speed-y># 2. via a Call Script command - fog will be added when the command is run# Call Script: $game_map.add_fog(name, hue, opacity, blend_type, zoom, # speed_x, speed_y)## Use the following two commands to make changes to fog# Call Script: $game_map.start_fog_tone_change(red, green, blue, gray, duration)# Call Script: $game_map.start_fog_opacity_change(opacity, duration)## You can also modify the $game_map fog attr_accessors individually via # Call Script commands.#----------------------------------------------------------------------------# Terms:# Use in free or commercial games# Credit Shaz#============================================================================module Cache#--------------------------------------------------------------------------# * Get Fog#--------------------------------------------------------------------------def self.fog(filename, hue) load_bitmap("Graphics/Fogs/", filename, hue)endendclass Game_Map#--------------------------------------------------------------------------# * Public Instance Variables#--------------------------------------------------------------------------attr_accessor :fog_name # fog file nameattr_accessor :fog_hue # fog hueattr_accessor :fog_opacity # fog opacity levelattr_accessor :fog_blend_type # fog blending methodattr_accessor :fog_zoom # fog zoom rateattr_accessor :fog_sx # fog sxattr_accessor :fog_sy # fog syattr_reader :fog_ox # fog x-coordinate starting pointattr_reader :fog_oy # fog y-coordinate starting pointattr_reader :fog_tone # fog color tone#--------------------------------------------------------------------------# * Setup#--------------------------------------------------------------------------alias shaz_fog_game_map_setup setupdef setup(map_id) shaz_fog_game_map_setup(map_id) setup_fog setup_notesend#--------------------------------------------------------------------------# * Setup Notes#--------------------------------------------------------------------------def setup_notes @map.note.split(/[\r\n+]/).each do |line| case line when /<fog\s*(\w+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)>/i @fog_name = $1 @fog_hue = $2.to_i @fog_opacity = $3.to_i @fog_blend_type = $4.to_i # 0-normal, 1-add, 2-sub @fog_zoom = $5.to_i @fog_sx = $6.to_i @fog_sy = $7.to_i end endend#--------------------------------------------------------------------------# * Setup Fog#--------------------------------------------------------------------------def setup_fog @fog_name = "" @fog_hue = 0 @fog_opacity = 0 @fog_blend_type = 0 @fog_zoom = 0 @fog_sx = 0 @fog_sy = 0 @fog_ox = 0 @fog_oy = 0 @fog_tone = Tone.new(0, 0, 0, 0) @fog_tone_target = Tone.new(0, 0, 0, 0) @fog_tone_duration = 0 @fog_opacity_duration = 0 @fog_opacity_target = 0end#--------------------------------------------------------------------------# * Add Fog#--------------------------------------------------------------------------def add_fog(name, hue = 90, opacity = 64, blend_type = 0, zoom = 200, sx = 0, sy = 0) @fog_name = name @fog_hue = hue @fog_opacity = opacity @fog_blend_type = blend_type @fog_zoom = zoom @fog_sx = sx @fog_sy = syend#--------------------------------------------------------------------------# * Start Changing Fog Color Tone# R, G, B, Gray : tone# duration : time#--------------------------------------------------------------------------def start_fog_tone_change(red, green, blue, gray, duration) @fog_tone_target = Tone.new(red, green, blue, gray) @fog_tone_duration = duration if @fog_tone_duration == 0 @fog_tone = @fog_tone_target.clone endend#--------------------------------------------------------------------------# * Start Changing Fog Opacity Level# opacity : opacity level# duration: time#--------------------------------------------------------------------------def start_fog_opacity_change(opacity, duration) @fog_opacity_target = opacity * 1.0 @fog_opacity_duration = duration if @fog_opacity_duration == 0 @fog_opacity = @fog_opacity_target endend#--------------------------------------------------------------------------# * Update Fog#--------------------------------------------------------------------------def update_fog @fog_ox -= @fog_sx / 8.0 @fog_oy -= @fog_sy / 8.0 # Manage change in fog color tone if @fog_tone_duration >= 1 d = @fog_tone_duration target = @fog_tone_target @fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d @fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d @fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d @fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d @fog_tone_duration -= 1 end # Manage change in fog opacity level if @fog_opacity_duration >= 1 d = @fog_opacity_duration @fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d @fog_opacity_duration -= 1 endend#--------------------------------------------------------------------------# * Frame Update# main:Interpreter update flag#--------------------------------------------------------------------------alias shaz_fog_game_map_update updatedef update(main = false) shaz_fog_game_map_update(main) update_fogendend#==============================================================================# ** Spriteset_Map#------------------------------------------------------------------------------#This class brings together map screen sprites, tilemaps, etc. It's used# within the Scene_Map class.#==============================================================================class Spriteset_Map#--------------------------------------------------------------------------# * Object Initialization#--------------------------------------------------------------------------alias shaz_fog_spriteset_map_initialize initializedef initialize shaz_fog_spriteset_map_initialize create_fog updateend#--------------------------------------------------------------------------# * Create Fog#--------------------------------------------------------------------------def create_fog @fog = Plane.new(@viewport1) @fog.z = 300end#--------------------------------------------------------------------------# * Free#--------------------------------------------------------------------------alias shaz_fog_spriteset_map_dispose disposedef dispose dispose_fog shaz_fog_spriteset_map_disposeend#--------------------------------------------------------------------------# * Free Fog#--------------------------------------------------------------------------def dispose_fog @fog.bitmap.dispose if @fog.bitmap @fog.disposeend#--------------------------------------------------------------------------# * Frame Update#--------------------------------------------------------------------------alias shaz_fog_spriteset_map_update updatedef update update_fog shaz_fog_spriteset_map_updateend#--------------------------------------------------------------------------# * Update Fog#--------------------------------------------------------------------------def update_fog return if !@fog if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue @fog_name = $game_map.fog_name @fog_hue = $game_map.fog_hue if @fog.bitmap != nil @fog.bitmap.dispose @fog.bitmap = nil end if @fog_name != "" @fog.bitmap = Cache.fog(@fog_name, @fog_hue) end Graphics.frame_reset end @fog.zoom_x = $game_map.fog_zoom / 100.0 @fog.zoom_y = $game_map.fog_zoom / 100.0 @fog.opacity = $game_map.fog_opacity @fog.blend_type = $game_map.fog_blend_type @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy @fog.tone = $game_map.fog_toneendend
FAQ
Credit and Thanks
- Credit Shaz
- Okay to use in commercial games
Author's Notes
本贴来自国际rpgmaker官方论坛作者:Shaz处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/xp-style-fog.17408/
页:
[1]