Chaos Project

RPG Maker => RPG Maker Scripts => Topic started by: Ryex on March 21, 2009, 11:36:56 pm

Title: BGM and SFX volume
Post by: Ryex on March 21, 2009, 11:36:56 pm
In my new CMS's option menu I'm including a master volume option. and while I'v implemented the masted volume in to the game and can change it when ever i want the change dose not take place until the scene or currently playing sound is changed. so I'm asking is there ang way to change the volume of the sound with out reseting the music.

this is how i did the master volume:

lass Game_System
 
  attr_accessor :bgm_volume
  attr_accessor :sfx_volume
  attr_accessor :ryexcmsfontname
  attr_accessor :ryexcmsfontsize
 
  alias init_ryex_cms_later initialize
  def initialize
    init_ryex_cms_later
    @bgm_volume = 100
    @sfx_volume = 100
    if @ryexcmsfontname == nil
      @ryexcmsfontname = 'Arial'
    end
    if @ryexcmsfontsize == nil
      @ryexcmsfontsize = 24
    end
    Font.default_name = @ryexcmsfontname
    Font.default_size = @ryexcmsfontsize

  end

  def bgm_play(bgm)
      @playing_bgm = bgm
      if bgm != nil && bgm.name != ''
        vol = @bgm_volume
        p vol
        p @bgm_volume
        Audio.bgm_play('Audio/BGM/' + bgm.name , bgm.volume * vol / 100, bgm.pitch)
      else
        Audio.bgm_stop
      end
      Graphics.frame_reset
    end
 
  def bgs_play(bgs)
    @playing_bgs = bgs
    if bgs != nil && bgs.name != ''
      vol = @sfx_volume
      Audio.bgs_play('Audio/BGS/' + bgs.name, bgs.volume * vol / 100, bgs.pitch)
    else
      Audio.bgs_stop
    end
    Graphics.frame_reset
  end
 
  def me_play(me)
    if me != nil && me.name != ''
      vol = @bgm_volume
      Audio.me_play('Audio/ME/' + me.name, me.volume * vol / 100, me.pitch)
    else
      Audio.me_stop
    end
    Graphics.frame_reset
  end

  def se_play(se)
    if se != nil && se.name != ''
      vol = @sfx_volume
      Audio.se_play('Audio/SE/' + se.name, se.volume * vol / 100, se.pitch)
    end
  end
end
class Array < Object
 
  def split(delimiter, elements)
    string = ''
    if elements == $data_system.elements
      if self.size > 0
        begin
          string += elements[self[0]]
          (1...self.size).each {|i|
            string += delimiter + elements[self[i]]
          }
        rescue
          string += elements[self[0]].to_s
          (1...self.size).each {|i|
            string += delimiter + elements[self[i]].to_s
          }
        end
      end
    elsif elements == $data_states
      if self.size > 0
        begin
          string += elements[self[0]].name
          (1...self.size).each {|i|
            string += delimiter + elements[self[i]].name
          }
        rescue
          string += elements[self[0]].name.to_s
          (1...self.size).each {|i|
            string += delimiter + elements[self[i]].name.to_s
          }
        end
      end
    end
    return string
  end

end

Title: Re: BGM and SFX volume
Post by: Blizzard on March 22, 2009, 01:36:53 pm
First off you don't need the part with "class Array". Secondly if you simply try to play the same music again that is already playing just with another volume, the music won't reset.
Title: Re: BGM and SFX volume
Post by: Ryex on March 22, 2009, 03:09:16 pm
so if i just do

bgm_play($game_system.playing_bgm)

the volume change will happen and the BGM position won't reset?

and the Class Array is for a different part of my cms that I copied by mistake
Title: Re: BGM and SFX volume
Post by: Blizzard on March 22, 2009, 04:06:55 pm
$game_system.bgm_play($game_system.playing_bgm)


And yes, it won't reset. It will only apply the volume. I think it does reset if you change the pitch, though.