#=========================================================================== # ◆ A1 Scripts ◆ # Audioフェードイン(RGSS3) # # バージョン : 1.20 (2012/01/03) # 作者 : A1 # URL     : http://a1tktk.web.fc2.com/ #--------------------------------------------------------------------------- # 機能: # ・BGMとBGSをフェードインさせます #--------------------------------------------------------------------------- # 更新履歴   :2012/01/03 Ver1.00 リリース #    :2012/01/03 Ver1.10 セーブできなくなる不具合を修正 #    :2012/01/03 Ver1.20 戦闘BGM制御対応 #--------------------------------------------------------------------------- # 設置場所 #  A1共通スクリプトより下 # # 必要スクリプト # A1共通スクリプトVer3.50以上 #--------------------------------------------------------------------------- # 使い方 # フェードインさせたい演奏の直後に「注釈」に記述 # # Audioフェードイン volume,time # volume:この値までフェードインします # time :フェードインにかける時間(ミリ秒 1000ミリ秒 = 1秒) # # 例:◆BGM の演奏:'Field3', 0, 100 ※ フェードインさせたいBGM/BGSを演奏 # ◆注釈:Audioフェードイン 100,3000 ※ 3秒かけてボリューム100までフェードイン # # ※演奏のボリュームは 0 を推奨 # # BGMとBGSの同時フェードインも可能 # # 例:◆BGM の演奏:'Field3', 0, 100 # ◆注釈:Audioフェードイン 100,3000 # ◆BGS の演奏:'Wind', 0, 100 # ◆注釈:Audioフェードイン 80,3000 # # ※BGM「Field3」とBGS「Wind」が同時にフェードインします #============================================================================== $imported ||= {} $imported["A1_AudioFadeIn"] = true if $imported["A1_Common_Script"] old_common_script("Audioフェードイン", "3.50") if common_version < 3.50 #============================================================================== # ■ A1_System::AudioFile #============================================================================== class A1_System::AudioFile #------------------------------------------------------------------------- # ○ 初期化 #------------------------------------------------------------------------- def initialize(audio, volume, time) audio_fadein(audio, volume, time) end #------------------------------------------------------------------------- # ○ Audioのフェードイン #------------------------------------------------------------------------- def audio_fadein(audio, volume, time) wait_time = time / volume if volume > 0 @fiber = Fiber.new { proc_audio_fadein(audio, volume, wait_time) } end #------------------------------------------------------------------------- # ○ Audioのフェードイン実行 #------------------------------------------------------------------------- def proc_audio_fadein(audio, volume, wait_time) (0..volume).each {|vol| wait_for_time(wait_time); audio.volume = vol; audio.play } clear_fiber end #------------------------------------------------------------------------- # ○ 時間待ち #------------------------------------------------------------------------- def wait_for_time(wait) break_time = $a1_common.now_usec + wait Fiber.yield while break_time > $a1_common.now_usec end #------------------------------------------------------------------------- # ○ ファイバーのクリア #------------------------------------------------------------------------- def clear_fiber @fiber = nil end #------------------------------------------------------------------------- # ○ フレーム更新 #------------------------------------------------------------------------- def update @fiber.resume if @fiber return @fiber end end #============================================================================== # ■ A1_System::CommonModule #============================================================================== class A1_System::CommonModule #-------------------------------------------------------------------------- # ☆ 注釈コマンド定義 #-------------------------------------------------------------------------- alias a1_audio_fadein_define_command define_command def define_command a1_audio_fadein_define_command @cmd_108["Audioフェードイン"] = :audio_fade_in end #-------------------------------------------------------------------------- # ☆ フレーム更新 #-------------------------------------------------------------------------- alias a1_audio_fadein_a1cmn_update update def update a1_audio_fadein_a1cmn_update update_audio end #-------------------------------------------------------------------------- # ○ Audioの更新 #-------------------------------------------------------------------------- def update_audio @fadein_bgm = nil unless @fadein_bgm.update if @fadein_bgm @fadein_bgs = nil unless @fadein_bgs.update if @fadein_bgs end #-------------------------------------------------------------------------- # ○ フェードインBGMの設定 #-------------------------------------------------------------------------- def fadein_bgm=(bgm) @fadein_bgm = bgm end #-------------------------------------------------------------------------- # ○ フェードインBGSの設定 #-------------------------------------------------------------------------- def fadein_bgs=(bgs) @fadein_bgs = bgs end end #============================================================================== # ■ Game_Interpreter #------------------------------------------------------------------------------ #  イベントコマンドを実行するインタプリタです。このクラスは Game_Map クラス、 # Game_Troop クラス、Game_Event クラスの内部で使用されます。 #============================================================================== class Game_Interpreter #-------------------------------------------------------------------------- # ○ 定数 #-------------------------------------------------------------------------- COMMAND_CODE = [241, 245] #-------------------------------------------------------------------------- # ☆ BGM の演奏 #-------------------------------------------------------------------------- alias a1_audio_fadein_command_241 command_241 def command_241 @fadein_bgm.clear_fiber if @fadein_bgm a1_audio_fadein_command_241 end #-------------------------------------------------------------------------- # ☆ BGS の演奏 #-------------------------------------------------------------------------- alias a1_audio_fadein_command_245 command_245 def command_241 @fadein_bgs.clear_fiber if @fadein_bgs a1_audio_fadein_command_245 end #-------------------------------------------------------------------------- # ○ Audioフェードイン #-------------------------------------------------------------------------- def audio_fade_in(params) prev_command = prev_event return unless COMMAND_CODE.include?(prev_command.code) audio_class = A1_System::AudioFile.new(prev_command.parameters[0], params[0].to_i, params[1].to_i) $a1_common.fadein_bgm = audio_class if prev_command.parameters[0].is_a?(RPG::BGM) $a1_common.fadein_bgs = audio_class if prev_command.parameters[0].is_a?(RPG::BGS) end end end