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.

need help making a method

I need help making a method for the game_system class to make bgs's fade IN. There is already an option to make them fade out so I don't know why they didn't include this. I'm pretty sure it would be similar to the fade out method:

#--------------------------------------------------------------------------
# * Fade Out Background Sound
# time : fade-out time (in seconds)
#--------------------------------------------------------------------------
def bgs_fade(time)
@playing_bgs = nil
Audio.bgs_fade(time * 1000)
end

________________________________________________________________________

I want to be able to call something like $game_system.bgs_fade_in("rain01", 60, 100, 50)

Here's the method & parameters that I would like to include:

def bgs_fade_in(bgs_name, time, volume, pitch)

My scripting skills aren't exactly top notch yet so I was wondering if I could get a little assistance to make this work.
 
*bump*

Oh come on, I know there's all kinds of scripting genius's at this forum. This should be a piece of cake for ya'll lol. Pleeaassee help me out. It would be greatly appreciated. I just don't like how a bgs (such as rain) just starts all of a sudden. I think it would be more realistic if it gradually faded in to your desired volume.
 
It's be a lot easier if we could see what the Audio module comprised of :P (where is it hidden btw, inside the RGSS dll? maybe someone should try disassembling it :D?)

But I guess you could just make a method with a while loop that decreases the volume with each iteration until it is 0.
 
Sure! The code in bold letters is what you add in the $game_system class.

Code:
  #----------------------------------------------------------
  # * Object Initialization
  #----------------------------------------------------------
  def initialize
    @map_interpreter = Interpreter.new(0, true)
    @battle_interpreter = Interpreter.new(0, false)
    @timer = 0
    @timer_working = false
    @save_disabled = false
    @menu_disabled = false
    @encounter_disabled = false
    @message_position = 2
    @message_frame = 0
    @save_count = 0
    @magic_number = 0
    [B]@bgs_fadein_update=false[/B] ######Don't update at start
  end

Code:
  #----------------------------------------------------------- ----
  # * Frame Update
  #----------------------------------------------------------- ----
  def update
    [B]update_bgs_fade_in[/B]  ################Update Fade In
    # reduce timer by 1
    if @timer_working and @timer > 0
      @timer -= 1
    end
  end

Then add these two methods:

Code:
  #----------------------------------------------------------- ----
  # * Fade In Background Sound
  #     name      : BGS Filename
  #     endvolume : BGS Maximum Volume
  #     pitch     : BGS Pitch
  #     time      : Fade-In Time (in frames)
  #----------------------------------------------------------- ----
  def bgs_fade_in(name,endvolume,pitch,time)
    @bgs_fadein_update = true
    @bgs_endvolume = endvolume
    @bgs_fadein_increase = endvolume.to_f / time.to_f
    @bgs_fadevolume = 0
    bgs = RPG::AudioFile.new(name,0,pitch)
    bgs_play(bgs)
  end
  #----------------------------------------------------------- ----
  # * Update BGS Fade In
  #----------------------------------------------------------- ----
  def update_bgs_fade_in
    return if @bgs_fadein_update==false
    @bgs_fadevolume += @bgs_fadein_increase
    #print(@bgs_fadevolume)
    @playing_bgs.volume = @bgs_fadevolume
    if @playing_bgs.volume >= @bgs_endvolume
      @playing_bgs.volume = @bgs_endvolume
      @bgs_fadein_update = false
    else
      bgs_play(@playing_bgs)
    end    
  end

And then you simply call
Code:
$game_system.bgs_fade_in(name,endvolume,pitch,time)

Pretty cool huh??
 

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