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

Project1

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

[已经过期] 音乐播放器脚本请求修正。

[复制链接]

Lv5.捕梦者

梦石
0
星屑
35138
在线时间
4164 小时
注册时间
2007-12-15
帖子
10061
跳转到指定楼层
1
发表于 2017-9-9 14:36:25 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

x
音乐播放器脚本,很久以前下的
使用方式是建立的道具公用事件
写上我看不懂什么意思的代码
$scene = Scene_music.new
# $scene 为有效的情况下调用 main 过程
while $scene != nil
   $scene.main
end
然后使用道具就而可以出现播放菜单,但是
一直有一些bug
比如用了以后存盘,再读盘就会存档损坏什么的
现在更好,直接给我跳这个,用都没法用了。
请问是什么原因,如何修正呢?



RUBY 代码复制
  1. #==============================================================================
  2. # ■ Scene_Title音乐播放脚本,来自日本网站[url]http://chronicle.onmitsu.jp[/url]
  3. #    由isul和link006007帮助修改
  4. #==============================================================================
  5.  
  6. class Scene_music
  7. #--------------------------------------------------------------------------
  8. # ● メイン処理
  9. #--------------------------------------------------------------------------
  10. def main
  11.   # データベースをロード
  12.   $data_system = load_data("Data/System.rxdata")
  13.   # システムオブジェクトを作成
  14.   $game_system = Game_System.new
  15.   # ファイルリストを作成
  16.   @filelist = Dir::entries("./Audio/BGM/")
  17.   @filelist.delete(".")
  18.   @filelist.delete("..")
  19.   if @filelist == []
  20.     # ウィンドウを作成
  21.     @filelist_window = Window_Base.new(0,0,360,480)
  22.     @filelist_window.contents = Bitmap.new(328,448)
  23.     @filelist_window.contents.font.color = Color.new(192, 224, 255, 255)
  24.     @filelist_window.contents.draw_text(0,100,328,32,"ファイルが見つかりません",1)
  25.     @filelist_window.contents.font.size = 16
  26.     @filelist_window.contents.font.color = Color.new(255, 255, 255, 255)
  27.     @filelist_window.contents.draw_text(0,150,328,32,"「Audio/BGM」フォルダに",1)
  28.     @filelist_window.contents.draw_text(0,182,328,32,"オーディオファイルを入れてください",1)
  29.   else
  30.     # ウィンドウを作成
  31.     @filelist_window = Window_Command.new(360, @filelist)
  32.     @filelist_window.height = 480
  33.     @filelist_window.x = 0
  34.     @filelist_window.y = 0
  35.   end
  36.   @s_status_window = Window_Sound_State.new(360,0,280,200)
  37.   @s_status_window.active = false
  38.   @key_help_window = Window_Key_Help.new(360,200,280,280)
  39.   @bgm = RPG::AudioFile.new
  40.   @bgm.volume = 100
  41.   @bgm.pitch = 100
  42.   # トランジション実行
  43.   Graphics.transition
  44.   # メインループ
  45.   loop do
  46.     # ゲーム画面を更新
  47.     Graphics.update
  48.     # 入力情報を更新
  49.     Input.update
  50.     # フレーム更新
  51.     update
  52.     # 画面が切り替わったらループを中断
  53.     if $scene != self
  54.       break
  55.     end
  56.   end
  57.   # トランジション準備
  58.   Graphics.freeze
  59.   # ウィンドウを解放
  60.   @filelist_window.dispose
  61.   @s_status_window.dispose
  62.   @key_help_window.dispose
  63. end
  64. #--------------------------------------------------------------------------
  65. # ● フレーム更新
  66. #--------------------------------------------------------------------------
  67. def update
  68.   if @filelist != []
  69.     @filelist_window.update
  70.     @s_status_window.update
  71.     # C ボタンが押された場合
  72.       if Input.trigger?(Input::C)
  73.       @bgm.name = @filelist[@filelist_window.index]
  74.       @s_status_window.set_data(@bgm)
  75.       $game_system.bgm_play(@bgm)
  76.     end
  77.  
  78.     # B ボタンが押された場合
  79.     if Input.trigger?(Input::B)
  80.       $game_system.bgm_stop
  81.        @filelist_window.dispose
  82.        @s_status_window.dispose
  83.        @key_help_window.dispose
  84.        $scene = Scene_Map.new
  85.        $game_map.autoplay
  86.       # $scene 为有效的情况下调用 main 过程
  87.        while $scene != nil
  88.            $scene.main
  89.         end
  90.  
  91.      end
  92.     # A ボタンが押された場合
  93.     if Input.trigger?(Input::A)
  94.       if @filelist_window.active
  95.         @filelist_window.active = false
  96.         @s_status_window.active = true
  97.         @key_help_window.refresh_vol
  98.       else
  99.         @s_status_window.active = false
  100.         @filelist_window.active = true
  101.         @key_help_window.refresh
  102.       end
  103.       @bgm.name = @filelist[@filelist_window.index]
  104.       @s_status_window.set_data(@bgm)
  105.     end
  106.   end
  107. end
  108. end
  109.  
  110. #==============================================================================
  111. # □ Window_Sound_State
  112. #==============================================================================
  113.  
  114. class Window_Sound_State < Window_Base
  115. #--------------------------------------------------------------------------
  116. # ○ オブジェクト初期化
  117. #     x      : ウィンドウの X 座標
  118. #     y      : ウィンドウの Y 座標
  119. #     width  : ウィンドウの幅
  120. #     height : ウィンドウの高さ
  121. #--------------------------------------------------------------------------
  122. def initialize(x, y, width, height)
  123.   super(x, y, width, height)
  124.   @bgm = RPG::AudioFile.new
  125.   self.contents = Bitmap.new(width - 32, height - 32)
  126. end
  127.  
  128. #--------------------------------------------------------------------------
  129. # ○ リフレッシュ
  130. #--------------------------------------------------------------------------
  131. def refresh
  132.   self.contents.clear
  133.   self.contents.font.size = 22
  134.   if self.active
  135.     self.contents.font.color = normal_color
  136.   else
  137.     self.contents.font.color = Color.new(255, 255, 64, 255)
  138.   end
  139.   rect = Rect.new(4, 16, self.contents.width - 8, 32)
  140.   self.contents.draw_text(rect, @bgm.name)
  141.   self.contents.font.color = normal_color
  142.   rect = Rect.new(4, 64, self.contents.width - 96, 32)
  143.   self.contents.draw_text(rect, "volume", 2)
  144.   rect = Rect.new(4, 96, self.contents.width - 96, 32)
  145.   self.contents.draw_text(rect, "pitch", 2)
  146.   if self.active
  147.     self.contents.font.size = 18
  148.     self.contents.font.color = system_color
  149.     rect = Rect.new(4, 64, self.contents.width - 12, 32)
  150.     self.contents.draw_text(rect, "↓    ↑", 2)
  151.     rect = Rect.new(4, 96, self.contents.width - 12, 32)
  152.     self.contents.draw_text(rect, "←    →", 2)
  153.     self.contents.font.color = Color.new(255, 255, 64, 255)
  154.   end
  155.   self.contents.font.size = 22
  156.   rect = Rect.new(4, 64, self.contents.width - 32, 32)
  157.   self.contents.draw_text(rect, @bgm.volume.to_s, 2)
  158.   rect = Rect.new(4, 96, self.contents.width - 32, 32)
  159.   self.contents.draw_text(rect, @bgm.pitch.to_s, 2)
  160. end
  161. #--------------------------------------------------------------------------
  162. # ○ サウンドデータをセット
  163. #--------------------------------------------------------------------------
  164. def set_data(bgm)
  165.   @bgm = bgm
  166.   refresh
  167. end
  168. #--------------------------------------------------------------------------
  169. # ○ フレーム更新
  170. #--------------------------------------------------------------------------
  171. def update
  172.   super
  173.   # カーソルの移動が可能な状態の場合
  174.   if self.active
  175.     # 方向ボタンの下が押された場合
  176.      if Input.repeat?(Input::DOWN)
  177.       if @bgm.volume > 0
  178.         @bgm.volume -= 5
  179.         set_data(@bgm)
  180.       end
  181.     end
  182.     # 方向ボタンの上が押された場合
  183.     if Input.repeat?(Input::UP)
  184.       if @bgm.volume < 100
  185.         @bgm.volume += 5
  186.         set_data(@bgm)
  187.       end
  188.     end
  189.     # 方向ボタンの右が押された場合
  190.     if Input.repeat?(Input::RIGHT)
  191.       if @bgm.pitch < 150
  192.         @bgm.pitch += 5
  193.         set_data(@bgm)
  194.       end
  195.     end
  196.     # 方向ボタンの左が押された場合
  197.     if Input.repeat?(Input::LEFT)
  198.       if @bgm.pitch > 50
  199.         @bgm.pitch -= 5
  200.         set_data(@bgm)
  201.       end
  202.     end
  203.   end
  204. end
  205. end
  206.  
  207. #==============================================================================
  208. # □ Window_Key_Help
  209. #==============================================================================
  210.  
  211. class Window_Key_Help < Window_Base
  212. #--------------------------------------------------------------------------
  213. # ○ オブジェクト初期化
  214. #--------------------------------------------------------------------------
  215. def initialize(x, y, width, height)
  216.   super(x, y, width, height)
  217.   self.contents = Bitmap.new(width - 32, height - 32)
  218.   self.opacity = 0
  219.   refresh
  220. end
  221. #--------------------------------------------------------------------------
  222. # ○ リフレッシュ(ファイルリスト)
  223. #--------------------------------------------------------------------------
  224. def refresh
  225.   self.contents.clear
  226.   self.contents.font.size = 20
  227.   rect = Rect.new(4, 0, self.contents.width - 8, 22)
  228.   self.contents.draw_text(rect, "- 说明 -",1)
  229.   self.contents.font.color = system_color
  230.   self.contents.font.size = 18
  231.   rect = Rect.new(100, 32, 180, 32)
  232.   self.contents.draw_text(rect, "Enter , Space , C")
  233.   rect = Rect.new(100, 64, 180, 32)
  234.   self.contents.draw_text(rect, "Esc , X , 0")
  235.   rect = Rect.new(100, 96, 180, 32)
  236.   self.contents.draw_text(rect, "Shift , Z")
  237.   rect = Rect.new(100, 128, 180, 32)
  238.   self.contents.draw_text(rect, "↑ , ↓")
  239.   self.contents.font.color = normal_color
  240.   self.contents.font.size = 22
  241.   rect = Rect.new(4, 32, 90, 32)
  242.   self.contents.draw_text(rect, "播放")
  243.   rect = Rect.new(4, 64, 90, 32)
  244.   self.contents.draw_text(rect, "停止")
  245.   rect = Rect.new(4, 96, 90, 32)
  246.   self.contents.draw_text(rect, "音乐选项")
  247.   rect = Rect.new(4, 128, 90, 32)
  248.   self.contents.draw_text(rect, "选曲")
  249. end
  250. #--------------------------------------------------------------------------
  251. # ○ リフレッシュ(ボリュームコントロール)
  252. #--------------------------------------------------------------------------
  253. def refresh_vol
  254.   self.contents.clear
  255.   self.contents.font.size = 20
  256.   rect = Rect.new(4, 0, self.contents.width - 8, 22)
  257.   self.contents.draw_text(rect, "- 说明 -",1)
  258.   self.contents.font.color = system_color
  259.   self.contents.font.size = 18
  260.   rect = Rect.new(100, 32, 180, 32)
  261.   self.contents.draw_text(rect, "↑ , ↓")
  262.   rect = Rect.new(100, 64, 180, 32)
  263.   self.contents.draw_text(rect, "← , →")
  264.   rect = Rect.new(100, 96, 180, 32)
  265.   self.contents.draw_text(rect, "Enter , Space , C")
  266.   rect = Rect.new(100, 128, 180, 32)
  267.   self.contents.draw_text(rect, "Esc , X , 0")
  268.   rect = Rect.new(100, 160, 180, 32)
  269.   self.contents.draw_text(rect, "Shift , Z")
  270.   self.contents.font.color = normal_color
  271.   self.contents.font.size = 22
  272.   rect = Rect.new(4, 32, 90, 32)
  273.   self.contents.draw_text(rect, "音量")
  274.   rect = Rect.new(4, 64, 90, 32)
  275.   self.contents.draw_text(rect, "速度")
  276.   rect = Rect.new(4, 96, 90, 32)
  277.   self.contents.draw_text(rect, "播放")
  278.   rect = Rect.new(4, 128, 90, 32)
  279.   self.contents.draw_text(rect, "停止")
  280.   rect = Rect.new(4, 160, 90, 32)
  281.   self.contents.draw_text(rect, "回主菜单")
  282. end
  283. end

Lv4.逐梦者

梦石
0
星屑
12157
在线时间
4435 小时
注册时间
2014-4-11
帖子
5955

开拓者

2
发表于 2017-9-9 21:59:37 | 只看该作者
我没有报错
while $scene != nil
   $scene.main
end
意思是 $scene不是不存在的情况下就执行 $scene的DEF main
由于上面$scene = Scene_music.new 了
所以就马上执行了 Scene_music的main
本来$scene = Scene_music.new 后还要等当前脚本结束后才会进入 Scene_music
这样写了后,就马上进入了 Scene_music,后面的不执行
回复 支持 反对

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
35138
在线时间
4164 小时
注册时间
2007-12-15
帖子
10061
3
 楼主| 发表于 2017-9-10 06:15:30 | 只看该作者
yang1zhi 发表于 2017-9-9 21:59
我没有报错
while $scene != nil
   $scene.main

还有个可能,我音乐数据库太大了,脚本无法全部调用,刚才进去一次,界面全是混乱的。
请问有没有类似的脚本,更加易用一些的。毕竟这脚本很老了,至少得6 7年前的了
现在也许有更高级的写法?
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-21 16:20

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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