Advertisement
MakerSystems

RPG Maker VX Ace - Audio Fade In

May 14th, 2015
1,842
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.47 KB | None | 0 0
  1. %Q(
  2. ╔════╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═════╗
  3. ║ ╔══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╗ ║
  4. ╠─╣ Audio Fade In ╠─╣
  5. ╠─╣ by RPG Maker Source. ╠─╣
  6. ╠─╣ www.rpgmakersource.com ╠─╣
  7. ║ ╚══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╝ ║
  8. ╠════╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═════╣
  9. ║ ┌────┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴─────┐ ║
  10. ╠─┤ Version 1.0.0 17/03/15 DD/MM/YY ├─╣
  11. ║ └────┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬─────┘ ║
  12. ╠══════╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══════╣
  13. ║ ║
  14. ║ This work is protected by the following license: ║
  15. ║ ╔══════════════════════════════════════════════════════════════════╗ ║
  16. ║ │ │ ║
  17. ║ │ Copyright © 2014 Maker Systems. │ ║
  18. ║ │ │ ║
  19. ║ │ This software is provided 'as-is', without any kind of │ ║
  20. ║ │ warranty. Under no circumstances will the author be held │ ║
  21. ║ │ liable for any damages arising from the use of this software. │ ║
  22. ║ │ │ ║
  23. ║ │ Permission is granted to anyone to use this software on their │ ║
  24. ║ │ free or commercial games made with a legal copy of RPG Maker │ ║
  25. ║ │ VX Ace, as long as Maker Systems - RPG Maker Source is │ ║
  26. ║ │ credited within the game. │ ║
  27. ║ │ │ ║
  28. ║ │ Selling this code or any portions of it 'as-is' or as part of │ ║
  29. ║ │ another code, is not allowed. │ ║
  30. ║ │ │ ║
  31. ║ │ The original header, which includes this copyright notice, │ ║
  32. ║ │ must not be edited or removed from any verbatim copy of the │ ║
  33. ║ │ sotware nor from any edited version. │ ║
  34. ║ │ │ ║
  35. ║ ╚══════════════════════════════════════════════════════════════════╝ ║
  36. ║ ║
  37. ║ ║
  38. ╠══════════════════════════════════════════════════════════════════════════════╣
  39. ║ 1. VERSION HISTORY. ▼ ║
  40. ╠══════════════════════════════════════════════════════════════════════════════╣
  41. ║ ║
  42. ║ • Version 1.0.0, 17/03/15 - (DD/MM/YY). ║
  43. ║ ║
  44. ╠══════════════════════════════════════════════════════════════════════════════╣
  45. ╠══════════════════════════════════════════════════════════════════════════════╣
  46. ║ 2. USER MANUAL. ▼ ║
  47. ╠══════════════════════════════════════════════════════════════════════════════╣
  48. ║ ║
  49. ║ ┌──────────────────────────────────────────────────────────────────────────┐ ║
  50. ║ │ ■ Introduction. │ ║
  51. ║ └┬┬┬┬──────────────────────────────────────────────────────────────────┬┬┬┬┘ ║
  52. ║ ║
  53. ║ Hello there! This script is "plug and play", you can simply insert it into ║
  54. ║ your project and it will perform flawlessly. ║
  55. ║ ║
  56. ║ This script adds the "fade in" function to the Audio channels, since by ║
  57. ║ default, only "fade out" is included as an event command. ║
  58. ║ ║
  59. ║ It is very easy to use, just add the correct command using a Call Script ║
  60. ║ event command after you use a Play BGM/BGS/ME one. ║
  61. ║ ║
  62. ║ We hope you enjoy it. ║
  63. ║ ║
  64. ║ Thanks for choosing our products. ║
  65. ║ ║
  66. ║ ┌──────────────────────────────────────────────────────────────────────────┐ ║
  67. ║ │ ■ Feature Documentation. │ ║
  68. ║ └┬┬┬┬──────────────────────────────────────────────────────────────────┬┬┬┬┘ ║
  69. ║ ║
  70. ║ The script commands that you can use inside a Script Call (Event Command) ║
  71. ║ are displayed inside the following chart, followed by their description ║
  72. ║ and, if needed, usage details and examples. ║
  73. ║ ║
  74. ║ ┌───────────────────────────────┐ ║
  75. ║ │ Audio.bgm_fadein(frames) │ ║
  76. ║ ├───────────────────────────────┴────────────────────────────────────────┐ ║
  77. ║ │ Use right after a Play BGM event command. │ ║
  78. ║ └────────────────────────────────────────────────────────────────────────┘ ║
  79. ║ ┌───────────────────────────────┐ ║
  80. ║ │ Audio.bgs_fadein(frames) │ ║
  81. ║ ├───────────────────────────────┴────────────────────────────────────────┐ ║
  82. ║ │ Use right after a Play BGS event command. │ ║
  83. ║ └────────────────────────────────────────────────────────────────────────┘ ║
  84. ║ ┌───────────────────────────────┐ ║
  85. ║ │ Audio.me_fadein(frames) │ ║
  86. ║ ├───────────────────────────────┴────────────────────────────────────────┐ ║
  87. ║ │ Use right after a Play ME event command. │ ║
  88. ║ └────────────────────────────────────────────────────────────────────────┘ ║
  89. ║ ║
  90. ╠══════════════════════════════════════════════════════════════════════════════╣
  91. ╠══════════════════════════════════════════════════════════════════════════════╣
  92. ║ 3. NOTES. ▼ ║
  93. ╠══════════════════════════════════════════════════════════════════════════════╣
  94. ║ ║
  95. ║ Have fun and enjoy! ║
  96. ║ ║
  97. ╠══════════════════════════════════════════════════════════════════════════════╣
  98. ╠══════════════════════════════════════════════════════════════════════════════╣
  99. ║ 4. CONTACT. ▼ ║
  100. ╠══════════════════════════════════════════════════════════════════════════════╣
  101. ║ ║
  102. ║ Keep in touch with us and be the first to know about new releases: ║
  103. ║ ║
  104. ║ www.rpgmakersource.com ║
  105. ║ www.facebook.com/RPGMakerSource ║
  106. ║ www.twitter.com/RPGMakerSource ║
  107. ║ www.youtube.com/user/RPGMakerSource ║
  108. ║ ║
  109. ║ Get involved! Have an idea for a system? Let us know. ║
  110. ║ ║
  111. ║ Spread the word and help us reach more people so we can continue creating ║
  112. ║ awesome resources for you! ║
  113. ║ ║
  114. ╚══════════════════════════════════════════════════════════════════════════════╝)
  115.  
  116. #==============================================================================
  117. # ** Audio
  118. #------------------------------------------------------------------------------
  119. # The module that carries out music and sound processing.
  120. #==============================================================================
  121.  
  122. module Audio
  123.  
  124. @bgm_volume = 100
  125. @bgs_volume = 100
  126. @me_volume = 100
  127. @se_volume = 100
  128.  
  129. class << self
  130.  
  131. #------------------------------------------------------------------------
  132. # * Public Instance Variables. [NEW]
  133. #------------------------------------------------------------------------
  134. attr_reader :bgm_volume, :bgs_volume, :me_volume, :se_volume
  135.  
  136. ['bgm', 'bgs', 'me', 'se'].each { |channel| class_eval %Q(
  137.  
  138. #------------------------------------------------------------------------
  139. # * Alias (BGM/BGS/ME/SE) Play. [NEW]
  140. #------------------------------------------------------------------------
  141. alias_method(:ms_audio_original_#{channel}_play, :#{channel}_play)
  142.  
  143. #------------------------------------------------------------------------
  144. # * (BGM/BGS/ME/SE) Play. [MOD]
  145. #------------------------------------------------------------------------
  146. def #{channel}_play(filename, volume = 100, pitch = 100, pos = 0)
  147. @now_#{channel} = [filename, volume, pitch, pos]
  148. volume = @#{channel}_volume * volume / 100
  149. if pos > 0
  150. ms_audio_original_#{channel}_play(filename, volume, pitch, pos)
  151. else
  152. ms_audio_original_#{channel}_play(filename, volume, pitch)
  153. end
  154. end
  155.  
  156. #------------------------------------------------------------------------
  157. # * Set (BGM/BGS/ME/SE) Volume. [NEW]
  158. #------------------------------------------------------------------------
  159. def #{channel}_volume=(value)
  160. value = 0 if value < 0
  161. value = 100 if value > 100
  162. @#{channel}_volume = value
  163. #{channel}_play(*@now_#{channel}) if @now_#{channel}
  164. end)
  165.  
  166. next if channel == 'se' ; class_eval %Q(
  167.  
  168. #------------------------------------------------------------------------
  169. # * (BGM/BGS/ME) Fade-In. [NEW]
  170. #------------------------------------------------------------------------
  171. def #{channel}_fadein(frames)
  172. @#{channel}_fade_step = 100.0 / frames.to_f
  173. @#{channel}_volume = 0
  174. end
  175.  
  176. #------------------------------------------------------------------------
  177. # * (BGM/BGS/ME) Update. [NEW]
  178. #------------------------------------------------------------------------
  179. def #{channel}_update
  180. @#{channel}_volume += @#{channel}_fade_step
  181. #{channel}_play(*@now_#{channel}) if @now_#{channel}
  182. @#{channel}_fade_step = nil if @#{channel}_volume >= 100.0
  183. end
  184.  
  185. #------------------------------------------------------------------------
  186. # * Alias (BGM/BGS/ME) Fade. [NEW]
  187. #------------------------------------------------------------------------
  188. alias_method(:ms_audio_original_#{channel}_fade, :#{channel}_fade)
  189.  
  190. #------------------------------------------------------------------------
  191. # * (BGM/BGS/ME) Fade. [MOD]
  192. #------------------------------------------------------------------------
  193. def #{channel}_fade(time)
  194. ms_audio_original_#{channel}_fade(time)
  195. end)}
  196.  
  197. #------------------------------------------------------------------------
  198. # * Update. [NEW]
  199. #------------------------------------------------------------------------
  200. def update
  201. bgm_update if @bgm_fade_step && @bgm_volume < 100
  202. bgs_update if @bgs_fade_step && @bgs_volume < 100
  203. me_update if @me_fade_step && @me_volume < 100
  204. end
  205.  
  206. end
  207.  
  208. end
  209.  
  210. #==============================================================================
  211. # ** Scene_Base
  212. #------------------------------------------------------------------------------
  213. # This is a super class of all scenes within the game.
  214. #==============================================================================
  215.  
  216. class Scene_Base
  217.  
  218. #--------------------------------------------------------------------------
  219. # * Alias Update Basic. [NEW]
  220. #--------------------------------------------------------------------------
  221. alias_method(:ms_audio_original_update_basic, :update_basic)
  222.  
  223. #--------------------------------------------------------------------------
  224. # * Update Basic. [NEW]
  225. #--------------------------------------------------------------------------
  226. def update_basic
  227. Audio.update
  228. ms_audio_original_update_basic
  229. end
  230.  
  231. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement