【原创】地图镜头移动、跟随
老脚本,使视野转向或跟随事件,用于剧情演出。范例:
https://www.123pan.com/s/uBKyVv-J6F3A.html 提取码:zoxX
脚本:
=begin
笔记:
$game_map.display_x,$game_map.display_y
指地图的卷动数值,以地图图块数为单位的浮点数
$game_player.real_x,$game_player.real_y
指玩家角色行走图在地图上的坐标,以地图图块数为单位的浮点数
$game_player.x,$game_playery
指玩家角色行走图在地图上的坐标,以地图图块数为单位的整数,即real_x,real_y值取整
=end
#==============================================================================
# 平滑镜头移动
# --by 烁灵
# 使用方法:
# 在【设置移动路径】中输入脚本
# start_move_screen_to_this
# 则镜头平滑转移向该事件(或角色)
# 在【设置移动路径】中输入脚本
# keep_screen_on
# 则镜头将跟随该事件(或角色,但不建议)
# 在【设置移动路径】中输入脚本
# keep_screen_off
# 则镜头将停止跟随该事件(或角色,但不建议)
#
#==============================================================================
Center_tile_x = ((Graphics.width - 32).to_i / 32 )/ 2 # 距离中心的格子数
Center_tile_y = ((Graphics.height - 32).to_i / 32 )/ 2 # 距离中心的格子数
Max_tile_num_x = Graphics.width / 32 # 地图每行最大图块数
Max_tile_num_y = Graphics.height / 32 # 地图每列最大图块数
class Game_Character < Game_CharacterBase
#--------------------------------------------------------------------------
# ● 初始化(追加定义)
#--------------------------------------------------------------------------
alias sl_orig_initialize initialize
def initialize
sl_orig_initialize
@screen_keep_up = false
@move_to_this = false
@scrollto_speed = 60
@scrollto_cnt = 0
end
#--------------------------------------------------------------------------
# ● 设置显示位置为地图中央(新增定义)
#--------------------------------------------------------------------------
def center(x, y)
# 自身坐标减去中心坐标,边边角角部分由set_display_pos修正
center_x = x - Center_tile_x
center_y = y - Center_tile_y
$game_map.set_display_pos(center_x, center_y)
end
#--------------------------------------------------------------------------
# ● 缓慢卷动到事件(新增定义)
#--------------------------------------------------------------------------
def scroll_to_this
@scrollto_cnt += 1
speed_x = (@distance_x.to_f / @scrollto_speed).abs
speed_y = (@distance_y.to_f / @scrollto_speed).abs
if @distance_x > 0
$game_map.scroll_right(speed_x)
else
$game_map.scroll_left(speed_x)
end
if @distance_y > 0
$game_map.scroll_down(speed_y)
else
$game_map.scroll_up(speed_y)
end
return @scrollto_cnt == @scrollto_speed
end
#--------------------------------------------------------------------------
# ● 开启跟踪(新增定义)
#--------------------------------------------------------------------------
def keep_screen_on
@screen_keep_up = true
end
#--------------------------------------------------------------------------
# ● 关闭跟踪(新增定义)
#--------------------------------------------------------------------------
def keep_screen_off
@screen_keep_up = false
end
#--------------------------------------------------------------------------
# ● 判断是否跟踪(新增定义)
#--------------------------------------------------------------------------
def screen_keep_up?
@screen_keep_up
end
#--------------------------------------------------------------------------
# ● 开启镜头移动(新增定义)
#--------------------------------------------------------------------------
def start_move_screen_to_this
@scrollto_cnt = 0
@move_to_this = true
start_x = $game_map.display_x
start_y = $game_map.display_y
if @real_x < Center_tile_x
@end_x = 0
elsif @real_x > $game_map.width - Max_tile_num_x + Center_tile_x
@end_x = $game_map.width - Max_tile_num_x
else
@end_x = @real_x - Center_tile_x
end
if @real_y < Center_tile_y
@end_y = 0
elsif @real_y > $game_map.height - Max_tile_num_y + Center_tile_y
@end_y = $game_map.height - Max_tile_num_y
else
@end_y = @real_y - Center_tile_y
end
@distance_x = @end_x - start_x
@distance_y = @end_y - start_y
end
#--------------------------------------------------------------------------
# ● 关闭镜头移动(新增定义)
#--------------------------------------------------------------------------
def stop_move_screen_to_this
@move_to_this = false
end
#--------------------------------------------------------------------------
# ● 判断镜头移动(新增定义)
#--------------------------------------------------------------------------
def move_to_this?
@move_to_this
end
#--------------------------------------------------------------------------
# ● 更新(追加定义)
#--------------------------------------------------------------------------
alias sl_orig_update update
def update
last_real_x = @real_x
last_real_y = @real_y
sl_orig_update
if screen_keep_up?
if @real_x > last_real_x
$game_map.scroll_right(@real_x - last_real_x)
else
$game_map.scroll_left(last_real_x - @real_x)
end
if @real_y > last_real_y
$game_map.scroll_down(@real_y - last_real_y)
else
$game_map.scroll_up(last_real_y - @real_y)
end
center(@real_x,@real_y)
end
end
end
class Scene_Map
alias kds_update update
def update
if $game_player.move_to_this?
$game_player.stop_move_screen_to_this if $game_player.scroll_to_this
end
for e in $game_map.events.values
if e.move_to_this?
e.stop_move_screen_to_this if e.scroll_to_this
end
end
kds_update
end
end
页:
[1]