设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 115|回复: 0

[转载发布] XP Style Fog

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    9071

    主题

    864

    回帖

    6万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    58883
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    68848

    灌水之王

    发表于 2026-8-1 10:49:14 | 显示全部楼层 |阅读模式
    XP Style Fog 1.0
    Shaz

    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:       
    1. <fog name hue opacity blend_type zoom speed-x speed-y>
    复制代码

    or via a Call Script command:
                    Code:       
    1. Call Script: $game_map.add_fog(name, hue, opacity, blend_type, zoom, speed_x, speed_y)
    复制代码

    Change fog via a Call Script command:
                    Code:       
    1. 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:       
    1. #============================================================================# 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 name  attr_accessor :fog_hue                  # fog hue  attr_accessor :fog_opacity              # fog opacity level  attr_accessor :fog_blend_type           # fog blending method  attr_accessor :fog_zoom                 # fog zoom rate  attr_accessor :fog_sx                   # fog sx  attr_accessor :fog_sy                   # fog sy  attr_reader   :fog_ox                   # fog x-coordinate starting point  attr_reader   :fog_oy                   # fog y-coordinate starting point  attr_reader   :fog_tone                 # fog color tone  #--------------------------------------------------------------------------  # * Setup  #--------------------------------------------------------------------------  alias shaz_fog_game_map_setup setup  def setup(map_id)    shaz_fog_game_map_setup(map_id)    setup_fog    setup_notes  end  #--------------------------------------------------------------------------  # * 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    end  end  #--------------------------------------------------------------------------  # * 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 = 0  end  #--------------------------------------------------------------------------  # * 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 = sy  end  #--------------------------------------------------------------------------  # * 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    end  end  #--------------------------------------------------------------------------  # * 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    end  end  #--------------------------------------------------------------------------  # * 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    end  end  #--------------------------------------------------------------------------  # * Frame Update  #     main:  Interpreter update flag  #--------------------------------------------------------------------------  alias shaz_fog_game_map_update update  def update(main = false)    shaz_fog_game_map_update(main)    update_fog  endend#==============================================================================# ** 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 initialize  def initialize    shaz_fog_spriteset_map_initialize    create_fog    update  end  #--------------------------------------------------------------------------  # * Create Fog  #--------------------------------------------------------------------------  def create_fog    @fog = Plane.new(@viewport1)    @fog.z = 300  end  #--------------------------------------------------------------------------  # * Free  #--------------------------------------------------------------------------  alias shaz_fog_spriteset_map_dispose dispose  def dispose    dispose_fog    shaz_fog_spriteset_map_dispose  end  #--------------------------------------------------------------------------  # * Free Fog  #--------------------------------------------------------------------------  def dispose_fog    @fog.bitmap.dispose if @fog.bitmap    @fog.dispose  end  #--------------------------------------------------------------------------  # * Frame Update  #--------------------------------------------------------------------------  alias shaz_fog_spriteset_map_update update  def update    update_fog    shaz_fog_spriteset_map_update  end  #--------------------------------------------------------------------------  # * 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_tone  endend
    复制代码





    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/
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-17 22:21 , Processed in 0.108776 second(s), 51 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表