Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Fade-In BGM

I found a script that fades in a BGM on a map, but I'd like a script that lets me fade it in from the call script command in event commands. I use fades alot during cutscenes.

It's a simple request really, just a callable script that will fade in a selected BGM over x seconds or x frames.

This request is sparce, but it really is that simple.

Anyone? :D
 
Code:
class Game_System
  
  def bgm_fadein(bgm, time, volume = 100)
    bgm_stop
    @bgm_targetvol = volume
    @bgm_fadestep = volume.to_f / time
    @playing_bgm = RPG::AudioFile.new(bgm, 0, 100)
    Audio.bgm_play("Audio/BGM/" + @playing_bgm.name, 0, 100)
  end
  
  def bgm_fadingin?
    return @bgm_targetvol != nil
  end
  
  def bgmfade_update
    vol = [@playing_bgm.volume + @bgm_fadestep, @bgm_targetvol].min
    @playing_bgm = RPG::AudioFile.new(@playing_bgm.name, vol, 100)
    Audio.bgm_play("Audio/BGM/" + @playing_bgm.name, @playing_bgm.volume.ceil, 100)
    unless vol.ceil < @bgm_targetvol
      @bgm_fadestep = nil
      @bgm_targetvol = nil
    end
  end
end

  
class Scene_Map
  alias old_update update
  def update
    old_update
    $game_system.bgmfade_update if $game_system.bgm_fadingin?
  end
end

Usage: $game_system.bgm_fadein(BGM_NAME, TIME, VOLUME)
Time is in frames, volume is optional (defaults to 100)

Next :)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top