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

Project1

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

[已经过期] 关于BGM播放的问题……

[复制链接]

Lv4.逐梦者

梦石
0
星屑
12540
在线时间
1443 小时
注册时间
2012-7-24
帖子
1302
跳转到指定楼层
1
发表于 2013-7-15 18:07:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
如题,在BGM播放时我用了MTV歌词显示脚本,但是有个问题:就是当BGM播放完一遍后会重新播放,但是歌词却不会重来,请问各位大神该怎么解决啊??脚本如下:
  1. #==============================================
  2. # 增加两个用来进行条件判断的临时变量
  3. #==============================================
  4. class Game_Temp
  5.    attr_accessor :old_text
  6.    attr_accessor :refresh_times
  7. alias meanfree_initialize initialize
  8. def initialize
  9.   meanfree_initialize
  10.   @old_text = ""
  11.   @refresh_times = 0
  12. end
  13. end

  14. module MTV  
  15. #===============================================================
  16. # 读取文件。文件相对地址:Audio/BGM
  17. # file_name:文件名;length:MTV长度,按照.1秒为单位记数
  18. #===============================================================
  19. def self.load(file_name,length = 0)
  20.   $mtv_time = []
  21.   $mtv_text = []
  22.   $game_system.mtv_length = length
  23.   #=============================================================
  24.   # 打开文件并且读取之
  25.   #=============================================================
  26.   file =  File.open("Audio/BGM/"+file_name)
  27.   #=============================================================
  28.   # 读取歌词
  29.   #=============================================================
  30.   for line in file.readlines
  31.     #===========================================================
  32.     # 转为UTF-8编码
  33.     #===========================================================
  34.     line = EasyConv.s2u(line)
  35.     #===========================================================
  36.     # 寻找本行歌词
  37.     #===========================================================
  38.     this_line_text = line[line.scan(/\]/).size*10,line.size]
  39.     #===========================================================
  40.     # 把读取的行分存成时间与文字
  41.     #===========================================================
  42.     for i in 0...line.scan(/\]/).size
  43.       temp_b = line[i*10+1,8]
  44.       temp_c = temp_b.split(/:/)[0]
  45.       mmsecond = 600 * temp_c.to_i
  46.       temp_c = temp_b.split(/:/)[1]
  47.       mmsecond += 10 * temp_c.to_f
  48.       $mtv_time.push(mmsecond.to_i)
  49.       $mtv_text.push(this_line_text)
  50.     end
  51.   end
  52.   file.close
  53. end
  54. #===============================================================
  55. # 开始MTV字幕
  56. #===============================================================
  57. def self.mtv_begin
  58.   $game_system.mtv_now = true
  59.   $game_system.mtv_begin_time = $sys_timer.now()
  60.   $lrc_text = ""
  61.   return
  62. end
  63. #===============================================================
  64. # 结束MTV字幕
  65. #===============================================================
  66. def self.stop
  67.   $game_system.mtv_now = false
  68.   return
  69. end
  70. #===============================================================
  71. # 测试MTV是否播放
  72. #===============================================================
  73. def self.mtv?
  74.   return $game_system.mtv_now
  75. end
  76. #===============================================================
  77. # 获取MTV字幕
  78. #===============================================================
  79. def self.new_text
  80.   if $game_system.mtv_now
  81.     #===========================================================
  82.     # 求出已经经过的时间
  83.     #===========================================================
  84.     nt = $sys_timer.now()
  85.     nt -= $game_system.mtv_begin_time
  86.     nt = nt.to_i
  87.     nt /= 100      
  88.     #===========================================================
  89.     # 制作循环
  90.     #===========================================================
  91.     if $game_system.mtv_length>0 and nt > $game_system.mtv_length
  92.       nt -= $game_system.mtv_length
  93.     end
  94.     #===========================================================
  95.     # 放出字幕
  96.     #===========================================================
  97.     for tm in 0...$mtv_time.size
  98.       if $mtv_time[tm] == nt
  99.         $lrc_text = $mtv_text[tm]
  100.         #=======================================
  101.         # 时间有限
  102.         $game_temp.old_text = $lrc_text
  103.         $game_temp.refresh_times += 1
  104.         # 面粉无敌
  105.         #=======================================
  106.         break
  107.       end
  108.     end
  109.   else
  110.     $lrc_text = ""
  111.   end
  112. end
  113. end
  114. # ------------------------------------------------------------------------
  115. # 高精度计时器 by FantasyDR
  116. # ------------------------------------------------------------------------
  117. # E-mail: [email protected]
  118. # ------------------------------------------------------------------------
  119. # 2005.10.18
  120. # ------------------------------------------------------------------------
  121. # 该类已经被定义为全局变量 $sys_timer
  122. # 如果只需要精确到毫秒,请设置初始化参数为true
  123. # decimal属性设置返回时间值的小数位数。
  124. # ------------------------------------------------------------------------
  125. # 下面是一些有用的方法列表,调用时写:$sys_timer.方法名
  126. # 例如 $sys_timer.clear()
  127. # ------------------------------------------------------------------------
  128. # clear() :计时器清零
  129. # now() :获取当前经过的时间,单位毫秒
  130. # now_s() :获取当前经过的时间,单位秒
  131. # ------------------------------------------------------------------------
  132. class SystemTimer
  133. attr_accessor:decimal #小数位数设定,默认为3

  134. def initialize(use_GetTime=false)
  135. # 初始化,根据系统选择不同精度计时器
  136. @qpFrequency = Win32API.new("kernel32","QueryPerformanceFrequency",'p','L')
  137. @qpCounter = Win32API.new("kernel32","QueryPerformanceCounter",'p','L')
  138. @tGetTime = Win32API.new("winmm","timeGetTime",'','L')

  139. @decimal=3
  140. @perf_cnt=" " * 8
  141. @time_start=" " * 8
  142. @time_now=" " * 8

  143. result = @qpFrequency.call(@perf_cnt)

  144. if use_GetTime
  145. result = 0
  146. end

  147. if result!=0
  148. @perf_flag=true
  149. else
  150. @perf_flag=false
  151. @perf_cnt=[1000,0].pack('LL')
  152. end

  153. #设置时间比例因数
  154. @time_scale=@perf_cnt.unpack('LL')
  155. @time_scale[0] /= 1000.0
  156. @time_scale[1] /= 1000.0

  157. #起始时间清零
  158. self.clear()
  159. end

  160. #-=====================-#
  161. # 计时器清零
  162. #-=====================-#
  163. def clear()
  164. if @perf_flag
  165. @qpCounter.call(@time_start)
  166. else
  167. @time_start=[@tGetTime.call(),0].pack('LL')
  168. end
  169. end

  170. #-==============================-#
  171. # 获取当前经过的时间,单位毫秒
  172. #-==============================-#
  173. def now()
  174. now_time = 0.0e1
  175. now_time += self.timer() - self.start()
  176. now_time /= self.scale()
  177. return self.debug(now_time)
  178. end

  179. #-==============================-#
  180. # 获取当前经过的时间,单位秒
  181. #-==============================-#
  182. def now_s()
  183. now_time = 0.0e1
  184. now_time += self.timer() - self.start()
  185. now_time /= (self.scale()*1000)
  186. return self.debug(now_time)
  187. end

  188. #-==============================-#
  189. # 帧错...
  190. #-==============================-#
  191. def debug(now_time)
  192. if @decimal>0
  193. now_time = (now_time * (10**@decimal)).floor/(10.0**@decimal)
  194. else
  195. now_time = now_time.floor
  196. end
  197. return now_time

  198. #以下用于debug模式
  199. if now_time < 0
  200. p "Timer Wrong!! Clear...",now_time,\
  201. @perf_flag,@qpCounter,@tGetTime,
  202. @time_now.unpack('LL')[0],@time_now.unpack('LL')[1],
  203. @time_start.unpack('LL')[0],@time_start.unpack('LL')[1]
  204. self.clear()
  205. return 0.0
  206. else
  207. return now_time
  208. end
  209. end

  210. #-=====================-#
  211. # 获取时间比例因数
  212. #-=====================-#
  213. def scale()
  214. return @time_scale[0]+\
  215. @time_scale[1]*0xffffffff
  216. end

  217. #-=====================-#
  218. # 获取起始滴答数
  219. #-=====================-#
  220. def start()
  221. return @time_start.unpack('LL')[0]+\
  222. @time_start.unpack('LL')[1]*0xffffffff
  223. end

  224. #-=====================-#
  225. # 获取当前的嘀哒数
  226. #-=====================-#
  227. def timer()
  228. if @perf_flag
  229. @qpCounter.call(@time_now)
  230. else
  231. @time_now=[@tGetTime.call(),0].pack('LL')
  232. end
  233. return @time_now.unpack('LL')[0]+\
  234. @time_now.unpack('LL')[1]*0xffffffff
  235. end
  236. end
  237. #-------------------------------------#
  238. # 初始化自身成一个全局变量
  239. #-------------------------------------#
  240. $sys_timer=SystemTimer.new()
  241. #-------------------------------------#

  242. #==============================================================================
  243. # 仭 EasyConv module - Ver 0.90
  244. #------------------------------------------------------------------------------
  245. # Moonlight INN
  246. # http://cgi.members.interq.or.jp/aquarius/rasetsu/
  247. # RaTTiE
  248. # [email protected]
  249. #------------------------------------------------------------
  250. # EasyConv::s2u(text) : S-JIS -> UTF-8
  251. # EasyConv::u2s(text) : UTF-8 -> S-JIS
  252. #==============================================================================
  253. module EasyConv
  254. # API梡掕悢掕媊
  255. CP_ACP = 0
  256. CP_UTF8 = 65001

  257. #--------------------------------------------------------------------------
  258. # 仠 S-JIS -> UTF-8
  259. #--------------------------------------------------------------------------
  260. def s2u(text)
  261. # API掕媊
  262. m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
  263. w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')

  264. # S-JIS -> Unicode
  265. len = m2w.call(CP_ACP, 0, text, -1, nil, 0);
  266. buf = "\0" * (len*2)
  267. m2w.call(CP_ACP, 0, text, -1, buf, buf.size/2);

  268. # Unicode -> UTF-8
  269. len = w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil);
  270. ret = "\0" * len
  271. w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil);

  272. return ret
  273. end
  274. # module_function偲偟偰岞奐
  275. module_function :s2u
  276. #--------------------------------------------------------------------------
  277. # 仠 UTF-8 -> S-JIS
  278. #--------------------------------------------------------------------------
  279. def u2s(text)
  280. # API掕媊
  281. m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
  282. w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')

  283. # UTF-8 -> Unicode
  284. len = m2w.call(CP_UTF8, 0, text, -1, nil, 0);
  285. buf = "\0" * (len*2)
  286. m2w.call(CP_UTF8, 0, text, -1, buf, buf.size/2);

  287. # Unicode -> S-JIS
  288. len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil);
  289. ret = "\0" * len
  290. w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil);

  291. return ret
  292. end
  293. # module_function偲偟偰岞奐
  294. module_function :u2s
  295. end


  296. #==============================================================================
  297. # ■ Game_System
  298. #------------------------------------------------------------------------------
  299. #  处理系统附属数据的类。也可执行诸如 BGM 管理之类的功能。本类的实例请参考
  300. # $game_system 。
  301. #==============================================================================
  302. class Game_System
  303. #--------------------------------------------------------------------------
  304. # ● 定义实例变量
  305. #--------------------------------------------------------------------------
  306. attr_accessor :mtv_begin_time
  307. attr_accessor :mtv_now
  308. attr_accessor :mtv_length
  309. #--------------------------------------------------------------------------
  310. # ● 初始化对像
  311. #--------------------------------------------------------------------------
  312. alias mtv_gamesystem_initialize initialize
  313. def initialize
  314.   mtv_gamesystem_initialize
  315.   @mtv_begin_time = $sys_timer.now()
  316.   @mtv_now = false
  317.   @mtv_length = 0
  318. end
  319. end  

  320. #==============================================================================
  321. # ■ Scene_Map
  322. #------------------------------------------------------------------------------
  323. #  处理地图画面的类。
  324. #==============================================================================
  325. class Scene_Map
  326. #--------------------------------------------------------------------------
  327. # ● 刷新画面
  328. #--------------------------------------------------------------------------
  329. alias mtv_scenemap_update update
  330. def update
  331.   MTV.new_text
  332.   @mtv_window.refresh
  333.   mtv_scenemap_update
  334. end
  335. #--------------------------------------------------------------------------
  336. # ● 主处理
  337. #--------------------------------------------------------------------------
  338. alias mtv_scenemap_main main
  339. def main
  340.   @mtv_window = Window_MTV.new
  341.   mtv_scenemap_main
  342.   @mtv_window.dispose
  343. end
  344. #--------------------------------------------------------------------------
  345. # ● 调用战斗 (调整自动切换BGM)
  346. #--------------------------------------------------------------------------
  347. def call_battle
  348.   # 清除战斗调用标志
  349.   $game_temp.battle_calling = false
  350.   # 清除菜单调用标志
  351.   $game_temp.menu_calling = false
  352.   $game_temp.menu_beep = false
  353.   # 生成遇敌计数
  354.   $game_player.make_encounter_count
  355.   # 记忆地图 BGM 、停止 BGM
  356.   $game_temp.map_bgm = $game_system.playing_bgm
  357.   unless MTV.mtv?      
  358.     $game_system.bgm_play($game_system.battle_bgm)
  359.     # 演奏战斗开始 SE
  360.     $game_system.se_play($data_system.battle_start_se)
  361.   end
  362.   # 矫正主角姿势
  363.   $game_player.straighten
  364.   # 切换到战斗画面
  365.   $scene = Scene_Battle.new
  366. end
  367. end

  368. #==============================================================================
  369. # ■ Scene_Battle
  370. #------------------------------------------------------------------------------
  371. #  处理战斗的类。
  372. #==============================================================================
  373. class Scene_Battle
  374. #--------------------------------------------------------------------------
  375. # ● 刷新画面
  376. #--------------------------------------------------------------------------
  377. alias mtv_scenebattle_update update
  378. def update
  379.   @mtv_window.refresh
  380.   mtv_scenebattle_update
  381. end
  382. #--------------------------------------------------------------------------
  383. # ● 主处理
  384. #--------------------------------------------------------------------------
  385. alias mtv_scenebattle_main main
  386. def main
  387.   @mtv_window = Window_MTV.new
  388.   mtv_scenebattle_main
  389.   @mtv_window.dispose
  390. end
  391. end

  392. #==============================================================================
  393. # ■ Window_MTV
  394. #------------------------------------------------------------------------------
  395. #  显示MTV字幕的窗口。
  396. #==============================================================================

  397. class Window_MTV < Window_Base
  398. #--------------------------------------------------------------------------
  399. # ● 初始化窗口
  400. #--------------------------------------------------------------------------
  401. def initialize
  402.   super(0, 416, 640, 64)
  403.   self.contents = Bitmap.new(width - 32, height - 32)
  404.   $lrc_text = ""
  405.   self.z = 9999
  406.   #===========================
  407.   # 时间有限
  408.   @temp_text = ""
  409.   $game_temp.old_text = ""
  410.   # 面粉无敌
  411.   #===========================
  412.   refresh

  413. end
  414. #--------------------------------------------------------------------------
  415. # ● 刷新
  416. #--------------------------------------------------------------------------
  417. def refresh(text = "")
  418.   #=================================================
  419.   # 时间有限
  420.   if $game_temp.in_battle
  421.     self.opacity = 0
  422.   else
  423.     self.opacity = 0
  424.   end
  425.   if $game_system.mtv_now == false or $lrc_text == ""
  426.     self.contents.clear
  427.     else
  428.   if $game_temp.refresh_times != 1
  429.     if $game_temp.old_text != @temp_text
  430.       self.contents.clear
  431.       self.contents.font.color = Color.new(0,0,0,255)
  432.       self.contents.draw_text(0, 0, 608, 32, $lrc_text, 1)   
  433.       self.contents.font.color = Color.new(255,255,255,255)
  434.       self.contents.draw_text(1, 1, 608, 32, $lrc_text, 1)
  435.       @temp_text = $lrc_text
  436.     end
  437.   else
  438.     self.contents.clear
  439.      self.contents.font.color = Color.new(0,0,0,255)
  440.       self.contents.draw_text(0, 0, 608, 32, $lrc_text, 1)   
  441.       self.contents.font.color = Color.new(255,255,255,255)
  442.       self.contents.draw_text(1, 1, 608, 32, $lrc_text, 1)
  443.       @temp_text = $lrc_text
  444.     end
  445.   end
  446.   # 面粉无敌
  447.   #==================================================
  448. end
  449. end
复制代码

点评

不好意思,这个我真不会······  发表于 2013-7-16 19:52

欢迎大家加我

Lv4.逐梦者

梦石
0
星屑
12540
在线时间
1443 小时
注册时间
2012-7-24
帖子
1302
2
 楼主| 发表于 2013-7-16 14:40:19 | 只看该作者
@baoer0804 @美丽晨露 就是当歌词显示完后再重头来一遍啊…………各位帮帮忙吧

欢迎大家加我
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
12540
在线时间
1443 小时
注册时间
2012-7-24
帖子
1302
3
 楼主| 发表于 2013-7-17 09:10:44 | 只看该作者
自顶一下哈~~版主莫怪……

欢迎大家加我
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
60
在线时间
568 小时
注册时间
2012-9-7
帖子
611
4
发表于 2013-7-17 09:39:14 | 只看该作者
你把要播放的BGM放到ME里面,播放ME不就得了?
FTM正式版已经发布,点击图片开启传送门
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
12540
在线时间
1443 小时
注册时间
2012-7-24
帖子
1302
5
 楼主| 发表于 2013-7-17 14:37:58 | 只看该作者
wingzeroplus 发表于 2013-7-17 09:39
你把要播放的BGM放到ME里面,播放ME不就得了?

请问你的意思是那样歌词能自动重新开始吗??是这样吗???

点评

呃……好像我理解错意思了……SORRY  发表于 2013-7-17 15:35

欢迎大家加我
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1337
在线时间
708 小时
注册时间
2010-9-22
帖子
178
6
发表于 2013-7-17 15:57:56 | 只看该作者
化螺耕 发表于 2013-7-16 14:40
@baoer0804 @美丽晨露 就是当歌词显示完后再重头来一遍啊…………各位帮帮忙吧  ...

没听明白什么意思?要是放一遍的话可以等其放完以后停止一下不就行了?还有就是可以记忆一下,下次接着放~是这个意思吗?
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
12540
在线时间
1443 小时
注册时间
2012-7-24
帖子
1302
7
 楼主| 发表于 2013-7-17 16:58:14 | 只看该作者
baoer0804 发表于 2013-7-17 15:57
没听明白什么意思?要是放一遍的话可以等其放完以后停止一下不就行了?还有就是可以记忆一下,下次接着放 ...

哦,可能我表述不到位啊……不应该把BGM给扯进来, 请你直接看我那个MTV歌词显示脚本,我是想要歌词显示完一遍后再来自动重新开始
PS:你的个性签名好漂亮啊,好期待你们工作室的《回到原点》啊

欢迎大家加我
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-23 04:31

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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