赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 3 |
经验 | 0 |
最后登录 | 2025-7-10 |
在线时间 | 21 小时 |
Lv2.观梦者
- 梦石
- 0
- 星屑
- 275
- 在线时间
- 21 小时
- 注册时间
- 2023-9-8
- 帖子
- 7
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
class Game_Message
attr_accessor :subtitle_text, :subtitle_duration, :subtitle_show_time
alias subtitle_clear clear
def clear
subtitle_clear
@subtitle_text = ""
@subtitle_duration = 0
@subtitle_show_time = 0
end
end
class Game_Interpreter
def play_se_with_subtitle(se, text, duration = 120)
Audio.se_play("Audio/SE/" + se.name, se.volume, se.pitch)
$game_message.subtitle_text = text.to_s
$game_message.subtitle_duration = duration.to_i
$game_message.subtitle_show_time = Graphics.frame_count
p "字幕已设置: #{text}" # 调试用
end
end
class Sprite_Subtitle < Sprite
def initialize(viewport = nil)
super(viewport)
refresh_bitmap
self.y = Graphics.height - 100
self.z = 999
self.opacity = 0
create_background
end
def create_background
@background = Sprite.new(viewport)
@background.bitmap = Bitmap.new(Graphics.width, 60)
@background.y = Graphics.height - 100
@background.z = 998
@background.opacity = 0
@background.bitmap.fill_rect(0, 0, Graphics.width, 60, Color.new(0, 0, 0, 180))
end
def refresh_bitmap
self.bitmap.dispose if self.bitmap
self.bitmap = Bitmap.new(Graphics.width, 60)
end
def update
super
if $game_message.subtitle_text != "" &&
Graphics.frame_count - $game_message.subtitle_show_time < $game_message.subtitle_duration
# 淡入
self.opacity += 25 if self.opacity < 255
@background.opacity += 25 if @background.opacity < 180
# 重绘文字
if @last_text != $game_message.subtitle_text
refresh_bitmap
self.bitmap.font.size = 22
self.bitmap.font.color = Color.new(255, 255, 255)
self.bitmap.font.outline = false
rect = Rect.new(0, 0, Graphics.width, 60)
self.bitmap.draw_text(rect, $game_message.subtitle_text, 1)
@last_text = $game_message.subtitle_text
end
else
# 淡出
self.opacity -= 25 if self.opacity > 0
@background.opacity -= 25 if @background.opacity > 0
$game_message.clear if self.opacity == 0
end
end
def dispose
super
@background.dispose if @background
self.bitmap.dispose if self.bitmap
end
end
class Spriteset_Map
alias subtitle_create_viewports create_viewports
alias subtitle_update update
alias subtitle_dispose dispose
def create_viewports
subtitle_create_viewports
@subtitle_sprite = Sprite_Subtitle.new(@viewport2)
end
def update
subtitle_update
@subtitle_sprite.update if @subtitle_sprite
end
def dispose
subtitle_dispose
@subtitle_sprite.dispose if @subtitle_sprite
end
end
class Scene_Map < Scene_Base
alias subtitle_update update
def update
subtitle_update
if Input.trigger?(:C) && $game_message.subtitle_text != ""
$game_message.clear
end
end
end
|
脚本命令格式:
play_se_with_subtitle(RPG::SE.new("文件名", 音量, 音调), "字幕内容", 持续时间帧数)
|
|