设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 42|回复: 0
打印 上一主题 下一主题

[原创发布] 仿半条命2音效字幕脚本

[复制链接]

Lv2.观梦者

梦石
0
星屑
275
在线时间
21 小时
注册时间
2023-9-8
帖子
7
跳转到指定楼层
1

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

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("文件名", 音量, 音调), "字幕内容", 持续时间帧数)

B18F74DBA237182E1D3F68DDB180E7A1.png (60.83 KB, 下载次数: 1)

B18F74DBA237182E1D3F68DDB180E7A1.png

BD26FFABAEAAA8B0363F3CA946CB5DEF.png (16.56 KB, 下载次数: 0)

BD26FFABAEAAA8B0363F3CA946CB5DEF.png
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2025-7-11 03:13

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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