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 |
B18F74DBA237182E1D3F68DDB180E7A1.png (60.83 KB, 下载次数: 4)
BD26FFABAEAAA8B0363F3CA946CB5DEF.png (16.56 KB, 下载次数: 2)
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |