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

Project1

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

[交流讨论] 文字声音 缓存优化版

[复制链接]

Lv2.观梦者

梦石
0
星屑
785
在线时间
59 小时
注册时间
2017-9-30
帖子
127
跳转到指定楼层
1
发表于 2017-12-1 09:16:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
因为在网页上此插件会重复读取音效,导致很卡,所以优化了下缓存
JAVASCRIPT 代码复制下载
  1. /*:
  2.  * @plugindesc
  3.  * v1.00 - 为事件的“显示文字”动作添加音效。
  4.  *
  5.  * @help
  6.  * 功能描述
  7.  *     本插件可以为事件的“显示文字”动作添加音效,让一些特定音效随文字一起出现。
  8.  * 使用方式
  9.  *     直接启用插件即可为文字添加音效。
  10.  *     你可以通过在事件中调用本系统提供的自定义脚本来修改音效的属性。(这些修改会永久生效,直到你下一次修改它们)
  11.  * 自定义脚本
  12.  *     set_text_sound_name("sound_name") # (字符串)将文字显示时播放的音效文件设置为sound_name(不含后缀名),音效存于audio/se目录下,你可以将"sound_name"改为null或""来关闭音效。
  13.  *     set_text_sound_interval(interval) # (整数)  设置为每interval个字播放一次音效
  14.  *     set_text_sound_volume(volume)     # (整数)  设置文字音效的音量
  15.  *     set_text_sound_pitch(pitch)       # (整数)  设置文字音效的音调
  16.  *     set_text_sound_pan(pan)           # (整数)  设置文字音效的偏移
  17.  * 脚本使用示例
  18.  *     set_text_sound_name("bell3")      # 设置文字显示时播放的音效为bell3
  19.  *     set_text_sound_interval(3)        # 设置文字每出现3个时播放1次音效
  20.  *     set_text_sound_volume(100)        # 设置文字音效的音量为100
  21.  *     set_text_sound_pitch(100)         # 设置文字音效的音调为100
  22.  *     set_text_sound_pan(0)             # 设置文字音效的偏移为0
  23.  * 功能特性
  24.  *     无论文字音效间隔是多少,对话内容的第一个文字永远会发声。
  25.  * 更新日志
  26.  *     v1.00 2015-11-4 23:26:12
  27.  *         发布。
  28.  *
  29.  * @param Text Sound Interval
  30.  * @desc 每多少个字播放一次音效,默认7
  31.  * @default 7
  32.  *
  33.  * @param Text Sound Name
  34.  * @desc 文字音效的文件名,默认Cursor1
  35.  * @default Cursor1
  36.  *
  37.  * @param Text Sound Volume
  38.  * @desc 文字音效的音量,默认100
  39.  * @default 100
  40.  *
  41.  * @param Text Sound Pitch
  42.  * @desc 文字音效的音调,默认100
  43.  * @default 100
  44.  *
  45.  * @param Text Sound Pan
  46.  * @desc 文字音效的偏移,默认0
  47.  * @default 0
  48.  */
  49.  
  50. (function() {
  51.  
  52.     //===========================================
  53.     // 插件参数
  54.     //===========================================
  55.  
  56.     var parameters = PluginManager.parameters('MessageTextSound');
  57.  
  58.     var text_current_frame = 0; // 当前的字数间隔计数
  59.     var text_se_interval = (parseInt(parameters['Text Sound Interval']) || 7); // 音效间隔,默认7
  60.     var text_se_object = new Object();
  61.     text_se_object.name = String(parameters['Text Sound Name'] || "Cursor1"); // 音效文件名,默认为"audio/se/Cursor1"
  62.     text_se_object.volume = (parseInt(parameters['Text Sound Volume']) || 100); // 音效音量,默认100
  63.     text_se_object.pitch = (parseInt(parameters['Text Sound Pitch']) || 100); // 音效音调,默认100
  64.     text_se_object.pan = (parseInt(parameters['Text Sound Pan']) || 0); // 音效偏移,默认0
  65.  
  66.     //===========================================
  67.     // 插件主体逻辑
  68.     //===========================================
  69.         function TextSound(){
  70.                 var buffer = null;
  71.                 this.playSe = function(se) {
  72.                         if (se.name) {
  73.                                 AudioManager._seBuffers = AudioManager._seBuffers.filter(function(audio) {
  74.                                         return audio.isPlaying();
  75.                                 });
  76.                                 if(buffer === null){
  77.                                         buffer = AudioManager.createBuffer('se', se.name);
  78.                                 }
  79.                                 AudioManager.updateSeParameters(buffer, se);
  80.                                 buffer.play(false);
  81.                                 AudioManager._seBuffers.push(buffer);
  82.                         }
  83.                 };
  84.         }
  85.         textSoundPlayer = new TextSound();
  86.  
  87.  
  88.     //-------------------------------------------
  89.     // 每当显示一个文字(包括转义符)时,播放音效
  90.     // 植入在updateShowFast而非在processCharacter是因为processCharacter会被其他类似的文字显示类调用
  91.     //-------------------------------------------
  92.     var _Window_Message_processNormalCharacter = Window_Message.prototype.processNormalCharacter;
  93.     Window_Message.prototype.processNormalCharacter = function(textState) {
  94.         // 回调原函数
  95.         if (text_current_frame >= text_se_interval) {
  96.             text_current_frame = 1;
  97.  
  98.             if ($gameSwitches.value(23)) {
  99.                 textSoundPlayer.playSe(text_se_object);
  100.             }
  101.             // 当前计数没到达发声阈,递增计数
  102.         } else {
  103.             text_current_frame = text_current_frame + 1;
  104.         }
  105.  
  106.         _Window_Message_processNormalCharacter.call(this, textState);
  107.  
  108.         // 当音效功能处于开启,并且对话不处于“快速显示”状态时进行计数
  109.         // if (!this._showFast && text_se_object.name != null && text_se_object.name != "") {
  110.         // 当前文字计数到达了发声阈,则播放声音,并重置计数
  111.  
  112.         // }
  113.     };
  114.  
  115.     //-------------------------------------------
  116.     // 消息框进入新的消息页时的处理
  117.     //-------------------------------------------
  118.  
  119.     var _Window_Message_newPage = Window_Message.prototype.newPage;
  120.     Window_Message.prototype.newPage = function(textState) {
  121.         // 自带:重置跳过本次后续音效的标记
  122.         _Window_Message_newPage.call(this, textState);
  123.         // 重置文字计数到发声阈值,用于在第一个字时发音
  124.         text_current_frame = text_se_interval;
  125.     };
  126.  
  127.     //===========================================
  128.     // 添加插件提供的自定义脚本
  129.     //===========================================
  130.  
  131.     // 设置音效文件名
  132.     set_text_sound_name = function(text) {
  133.         if (text == "" || text == null) {
  134.             text_se_object.name = null;
  135.         } else {
  136.             text_se_object.name = text;
  137.         }
  138.     }
  139.  
  140.     // 设置音效播放间隔(每多少个文字播放一次音效)
  141.     set_text_sound_interval = function(interval) {
  142.         text_se_interval = interval;
  143.     }
  144.  
  145.     // 设置音效的音量属性
  146.     set_text_sound_volume = function(volume) {
  147.         text_se_object.volume = volume;
  148.     }
  149.  
  150.     // 设置音效的音调属性
  151.     set_text_sound_pitch = function(pitch) {
  152.         text_se_object.pitch = pitch;
  153.     }
  154.  
  155.     // 设置音效的偏移属性
  156.     set_text_sound_pan = function(pan) {
  157.         text_se_object.pan = pan;
  158.     }
  159.  
  160. })();


评分

参与人数 1+1 收起 理由
青鸫 + 1 RUA!

查看全部评分

Lv4.逐梦者

梦石
0
星屑
5146
在线时间
604 小时
注册时间
2017-10-21
帖子
348
2
发表于 2017-12-1 10:31:39 | 只看该作者
前排支持!!!
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
帖子
1516
3
发表于 2017-12-1 17:03:57 | 只看该作者
可以做游戏语音了..

点评

不考虑效果好坏的话,确实可以做啊,原理其实差不多.  发表于 2017-12-3 23:56
不,这个只是文字的声音  发表于 2017-12-1 18:17
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-11 13:27

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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