#==============================================================================
# 动态远景 [VA]
# 版本: 1.0
# 作者: modern algebra (rmrk.net)
# 发布日期: 2011.12.20
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 概要:
# 本脚本用于设置多帧动态远景图,并可以自定义切换速率。
# 默认状态下脚本支持.png,.jpg,.bmp文件格式,我只知道VA支持这些格式。
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 使用说明:
#
# 本脚本可用于设置多帧动态远景图,并支持自定义切换速率,
# 允许每张地图都做不同的设置。
# 为了使用动态远景图,你需要先做以下准备工作:
# (a) 制作或寻找一系列你打算使用的背景图,并且将它们以统一格式命名:
# 文件名_数字序号(作为后缀。)
# 例如起名为:
# BlueSky_1, BlueSky_2, BlueSky_3, ...
# (b) 在地图上的“远景图”项目勾选上后缀序号为1的远景图,以便确定循环的开始。
# 如果不这样选则会在循环时漏掉序号更前的帧。例如,有BlueSky_1,_2,_3
# 3张图你设置了BlueSky_1,而不是另外两张。如果从BlueSky_2开始的话,
# 你的远景图就只会在_2和_3两张图上进行循环切换。
# (c) 找到本脚本第83行起的区域,按照提示进行恰当的编辑,
# 以设定在不同地图的切换速率。
#``````````````````````````````````````````````````````````````````````````````
# 在你需要改变地图切换速率的场合(例如,若你用事件改变了该地图显示的远景图),
# 你可以在事件脚本中书写以下语句:
#
# change_parallax_animation_speed(x)
# x: 切换到下一张之前所等待的帧数,60帧为1秒。
#
# 注意: 请不要在speed后面加额外的空格.
# change_parallax_animation_speed(x) <- 有效
# change_parallax_animation_speed (x) <- 无效
#
# 你亦可在括号中填写数组,以控制远景图切换的不同节奏;有些帧维持得比其他帧更久。
# 为此你需要将每两张远景图之间的等待帧数都依次写出来,并以半角逗号","分隔。
#
# change_parallax_animation_speed(x1, x2, ..., xn)
#
# 书写的规则照着40行的代码来就好.
#
# 例如:
#
# change_parallax_animation_speed(30)
# 在切换前,每张远景图都会逗留0.5秒,然后切换下一张
#
# change_parallax_animation_speed(15, 30, 60, 45)
# 第一张远景逗留0.25秒后切换;第二张远景逗留0.5秒;第三张远景逗留1秒;
# 第四张远景逗留0.75秒。并且以这一顺序循环重复进行。
#==============================================================================
$imported = {} unless $imported
$imported[:MA_AnimatedParallax] = true
#==============================================================================
# ** Game Map
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 改动的地方:
# 新增常量:MAAP_PARALLAX_ANIMATION_FRAMES; MAAP_PRELOAD_PARALLAXES
# MAAP_SUPPORTED_EXTENSIONS
# 重命名的旧方法:setup_parallax; change_parallax; update_parallax
# 新增方法;setup_parallax_frames; maap_check_extensions
#==============================================================================
class Game_Map
MAAP_PARALLAX_ANIMATION_FRAMES = { # <- 不要碰!
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
# 使用者可编辑区
#|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# MAAP_PARALLAX_ANIMATION_FRAMES - 该常数可用于设定地图切换远景图的帧率。
# 若你期望在某地图以20帧1张的速率切换背景,而在另外的地图以35帧一张的速率切换,
# 请在这里编辑。请遵照以下格式书写代码:
#
# 地图ID => 停留时间的帧数,
#
# 左边书写地图的ID,右边书写切换远景图前,原远景图停留的帧数,需填写整数或数组。
# 整数是切换到下一张之前所等待的帧数,60帧为1秒。数组的书写格式是半角中括号。
# 每两张远景图之间的等待帧数都需要依次写出来。
#
# 例如:
# 1 => 35, 1号地图以35帧每张的速率循环切换背景
# 2 => 40, 2号地图以40帧每张的速率循环切换背景
# 8 => [20, 5, 15], 8号地图第一张远景图会停留20帧再切换成第二张,
# 接着第二张会停留5帧再切换到第三张,第三张停留15帧并继续切换。
# 并循环往复。
#
# 注意,别漏了半角逗号! 对任何地图都可在本表中像这样设置。若没有额外设置,
# 则会采用这一默认值: MAAP_PARALLAX_ANIMATION_FRAMES.default.
1 => 20,
8 => 40,
} # <- 不要碰!
# 以下这个值是默认值,用于表示默认状态切换远景等待的帧数。
# 如果没有在上表中设定切换帧数,则按照以下的默认值进行切换。
MAAP_PARALLAX_ANIMATION_FRAMES.default = 30
# 若你选作背景的图片太大或用于切换的图数目太多,在载入新图片组的时候可能会卡。
# 为了改善这一现象,以下提供了一个选项,让你决定是否在初次进入某张地图,
# 或在对一次性读入图片组所有内容有所需求时,将图片读入缓存。
# 通常来说,如果你的远景图很大(1MB以上),设置true效果较好;
# 如果图片很小则设置false较好。
MAAP_PRELOAD_PARALLAXES = true
#|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# 可编辑区结束
#///////////////////////////////////////////////////////////////////////////
MAAP_SUPPORTED_EXTENSIONS = ["png", "jpg", "bmp"]
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Setup Parallax
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias ma_anmp_setuplax_6id3 setup_parallax
def setup_parallax(*args, &block)
ma_anmp_setuplax_6id3(*args, &block) # Run Original Method
setup_parallax_frames
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Change Parallax
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias moda_ap_chngprlx_8uz2 change_parallax
def change_parallax(*args, &block)
moda_ap_chngprlx_8uz2(*args, &block) # Run Original Method
setup_parallax_frames
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Update Parallax
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias maba_ap_updprx_9hv3 update_parallax
def update_parallax(*args, &block)
maba_ap_updprx_9hv3(*args, &block) # Run Original Method
# Use the timer if the parallax has more than one frame
if @maap_parallax_frames && @maap_parallax_frames.size > 1
@maap_parallax_frame_timer += 1
# Check if timer exceeded
if @maap_parallax_frame_timer >= @maap_frame_speed
@maap_parallax_frame_timer = 0 # Reset Timer
# Set parallax to next frame
@maap_parallax_index = (@maap_parallax_index + 1) % @maap_parallax_frames.size
@parallax_name = @maap_parallax_frames[@maap_parallax_index]
set_parallax_frame_speed(@maap_parallax_speed, @maap_parallax_index)
end
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Set Parallax Animation Speed
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def set_parallax_frame_speed(parallax_speed = MAAP_PARALLAX_ANIMATION_FRAMES[@map_id], frame = 0)
@maap_parallax_speed = parallax_speed
if @maap_parallax_speed.is_a?(Array)
@maap_frame_speed = [@maap_parallax_speed[frame], @maap_parallax_speed.compact[0]].compact[0]
else
@maap_frame_speed = @maap_parallax_speed
end
# Get the default setting, in case the time limit is incorrectly set
unless @maap_frame_speed.is_a?(Integer)
p "Error: Animated Parallax 1.0\nFrame Speed incorrectly set for #{@map_id}, frame #{frame + 1} - #{@parallax_name}"
@maap_frame_speed = MAAP_PARALLAX_ANIMATION_FRAMES.default
@maap_frame_speed = default.compact[0] if @maap_frame_speed.is_a?(Array)
@maap_frame_speed = 30 if !@maap_frame_speed
end
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Setup Parallax Frames
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def setup_parallax_frames
# Retain the names of old map's parallax, for disposal
last_map_bmps = @maap_parallax_frames.nil? ? [] : @maap_parallax_frames
# Initialize Data
@maap_parallax_index = 0
@maap_parallax_frames = [@parallax_name]
@maap_parallax_frame_timer = 0
set_parallax_frame_speed
# Collect all frames of the parallax animation
if @parallax_name[/_(\d+)$/] != nil
frame_id = $1.to_i + 1
base_name = @parallax_name.sub(/_\d+$/, "")
while maap_check_extensions("Graphics/Parallaxes/#{base_name}_#{frame_id}")
@maap_parallax_frames.push("#{base_name}_#{frame_id}")
frame_id += 1
end
end
# Dispose the cached bitmaps from the previous map
(last_map_bmps - @maap_parallax_frames).each { |bmp| (Cache.parallax(bmp)).dispose }
# Preload all the parallax bitmaps so no lag is experienced on first load
if MAAP_PRELOAD_PARALLAXES
(@maap_parallax_frames - last_map_bmps).each { |bmp| Cache.parallax(bmp) }
end
Graphics.frame_reset
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Check Extensions
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def maap_check_extensions (filepath)
MAAP_SUPPORTED_EXTENSIONS.any? { |ext| FileTest.exist?("#{filepath}.#{ext}") }
end
end
#==============================================================================
# ** Game_Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 改动的地方:
# 添加新方法change_parallax_animation_speed
#==============================================================================
class Game_Interpreter
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Change Parallax Animation Speed
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def change_parallax_animation_speed(*args)
if args.size <= 1
$game_map.set_parallax_frame_speed(*args)
else
$game_map.set_parallax_frame_speed(args)
end
end
end
#==============================================================================
# ** Spriteset Map
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# 改动的地方:
# 重命名update_parallax这个方法
#==============================================================================
class Spriteset_Map
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Update Parallax
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias ma_animpara_updlax_7ig8 update_parallax
def update_parallax(*args, &block)
# 请勿释放远景层图片!
@parallax.bitmap = nil if @parallax_name != $game_map.parallax_name
ma_animpara_updlax_7ig8(*args, &block) # Run Original Method
end
end