查看: 3734|回复: 4

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

[复制链接]
梦石
0
星屑
785
在线时间
59 小时
注册时间
2017-9-30
回帖
118
发表于 2017-12-1 09:16:08 | 显示全部楼层 |阅读模式

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

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

×
因为在网页上此插件会重复读取音效,导致很卡,所以优化了下缓存
  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. (function() {

  50.     //===========================================
  51.     // 插件参数
  52.     //===========================================

  53.     var parameters = PluginManager.parameters('MessageTextSound');

  54.     var text_current_frame = 0; // 当前的字数间隔计数
  55.     var text_se_interval = (parseInt(parameters['Text Sound Interval']) || 7); // 音效间隔,默认7
  56.     var text_se_object = new Object();
  57.     text_se_object.name = String(parameters['Text Sound Name'] || "Cursor1"); // 音效文件名,默认为"audio/se/Cursor1"
  58.     text_se_object.volume = (parseInt(parameters['Text Sound Volume']) || 100); // 音效音量,默认100
  59.     text_se_object.pitch = (parseInt(parameters['Text Sound Pitch']) || 100); // 音效音调,默认100
  60.     text_se_object.pan = (parseInt(parameters['Text Sound Pan']) || 0); // 音效偏移,默认0

  61.     //===========================================
  62.     // 插件主体逻辑
  63.     //===========================================
  64.         function TextSound(){
  65.                 var buffer = null;
  66.                 this.playSe = function(se) {
  67.                         if (se.name) {
  68.                                 AudioManager._seBuffers = AudioManager._seBuffers.filter(function(audio) {
  69.                                         return audio.isPlaying();
  70.                                 });
  71.                                 if(buffer === null){
  72.                                         buffer = AudioManager.createBuffer('se', se.name);
  73.                                 }
  74.                                 AudioManager.updateSeParameters(buffer, se);
  75.                                 buffer.play(false);
  76.                                 AudioManager._seBuffers.push(buffer);
  77.                         }
  78.                 };
  79.         }
  80.         textSoundPlayer = new TextSound();
  81.        
  82.        
  83.     //-------------------------------------------
  84.     // 每当显示一个文字(包括转义符)时,播放音效
  85.     // 植入在updateShowFast而非在processCharacter是因为processCharacter会被其他类似的文字显示类调用
  86.     //-------------------------------------------
  87.     var _Window_Message_processNormalCharacter = Window_Message.prototype.processNormalCharacter;
  88.     Window_Message.prototype.processNormalCharacter = function(textState) {
  89.         // 回调原函数
  90.         if (text_current_frame >= text_se_interval) {
  91.             text_current_frame = 1;

  92.             if ($gameSwitches.value(23)) {
  93.                 textSoundPlayer.playSe(text_se_object);
  94.             }
  95.             // 当前计数没到达发声阈,递增计数
  96.         } else {
  97.             text_current_frame = text_current_frame + 1;
  98.         }

  99.         _Window_Message_processNormalCharacter.call(this, textState);

  100.         // 当音效功能处于开启,并且对话不处于“快速显示”状态时进行计数
  101.         // if (!this._showFast && text_se_object.name != null && text_se_object.name != "") {
  102.         // 当前文字计数到达了发声阈,则播放声音,并重置计数

  103.         // }
  104.     };

  105.     //-------------------------------------------
  106.     // 消息框进入新的消息页时的处理
  107.     //-------------------------------------------

  108.     var _Window_Message_newPage = Window_Message.prototype.newPage;
  109.     Window_Message.prototype.newPage = function(textState) {
  110.         // 自带:重置跳过本次后续音效的标记
  111.         _Window_Message_newPage.call(this, textState);
  112.         // 重置文字计数到发声阈值,用于在第一个字时发音
  113.         text_current_frame = text_se_interval;
  114.     };

  115.     //===========================================
  116.     // 添加插件提供的自定义脚本
  117.     //===========================================

  118.     // 设置音效文件名
  119.     set_text_sound_name = function(text) {
  120.         if (text == "" || text == null) {
  121.             text_se_object.name = null;
  122.         } else {
  123.             text_se_object.name = text;
  124.         }
  125.     }

  126.     // 设置音效播放间隔(每多少个文字播放一次音效)
  127.     set_text_sound_interval = function(interval) {
  128.         text_se_interval = interval;
  129.     }

  130.     // 设置音效的音量属性
  131.     set_text_sound_volume = function(volume) {
  132.         text_se_object.volume = volume;
  133.     }

  134.     // 设置音效的音调属性
  135.     set_text_sound_pitch = function(pitch) {
  136.         text_se_object.pitch = pitch;
  137.     }

  138.     // 设置音效的偏移属性
  139.     set_text_sound_pan = function(pan) {
  140.         text_se_object.pan = pan;
  141.     }

  142. })();
复制代码


评分

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

查看全部评分

梦石
0
星屑
5185
在线时间
611 小时
注册时间
2017-10-21
回帖
321
发表于 2017-12-1 10:31:39 | 显示全部楼层
前排支持!!!
回复

使用道具 举报

梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
回帖
1464
发表于 2017-12-1 17:03:57 | 显示全部楼层
可以做游戏语音了..

点评

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

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部