Bigace360

Scene_Base[RMXP]

May 19th, 2012
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.76 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  2. # ■ Scene_Base [RMXP]
  3. # ■ Author: Bigace360
  4. # ■ Date: Feb 20, 2012
  5. # ■ Version: 1.1
  6. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  7. #   This script was designed to act as a parent class for all scenes. It
  8. #   provides 2 major purposes :
  9. #
  10. #    1) Give the Main Processing Method a Common Structure
  11. #    2) Automatically Update & Dispose All Spritesets, Sprites, Windows or
  12. #       any other instance variable that responds to :update or :dispose
  13. #
  14. #   This is a script for developers, not non-scripters. If you do not
  15. #   plan to create scenes in RMXP, this isn't needed.
  16. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  17. class Scene_Base
  18.     #--------------------------------------------------------------------------
  19.     # * Main Processing
  20.     #--------------------------------------------------------------------------
  21.     def main
  22.         start                                  # Start processing
  23.         post_start                             # Post-start processing
  24.         loop {main_loop; break if main_break?} # Scene Loop
  25.         move_windows                           # Move windows process
  26.         terminate                              # Termination processing
  27.         Graphics.update                        # Update game screen
  28.     end
  29.     #--------------------------------------------------------------------------
  30.     # * Start processing
  31.     #--------------------------------------------------------------------------
  32.     def start
  33.         create_main_viewport   
  34.     end
  35.     #--------------------------------------------------------------------------
  36.     # * Post-Start Processing
  37.     #--------------------------------------------------------------------------
  38.     def post_start
  39.         perform_transition
  40.         Input.update
  41.     end
  42.     #--------------------------------------------------------------------------
  43.     # * Execute Transition
  44.     #--------------------------------------------------------------------------
  45.     def perform_transition
  46.         Graphics.transition(transition_speed)
  47.     end
  48.     #--------------------------------------------------------------------------
  49.     # * Get Transition Speed
  50.     #--------------------------------------------------------------------------
  51.     def transition_speed
  52.         return 10
  53.     end
  54.     #--------------------------------------------------------------------------
  55.     # * Main Processing : Loop
  56.     #--------------------------------------------------------------------------
  57.     def main_loop
  58.         Graphics.update
  59.         Input.update
  60.         update_all_windows
  61.         update
  62.     end
  63.     #--------------------------------------------------------------------------
  64.     # * Frame Update
  65.     #--------------------------------------------------------------------------
  66.     def update; end
  67.     #--------------------------------------------------------------------------
  68.     # * Main Processing : Break Loop Test
  69.     #--------------------------------------------------------------------------
  70.     def main_break?
  71.         return $scene != self
  72.     end
  73.     #--------------------------------------------------------------------------
  74.     # * Move windows process
  75.     #--------------------------------------------------------------------------    
  76.     def move_windows; end
  77.     #--------------------------------------------------------------------------
  78.     # * Termination Processing
  79.     #--------------------------------------------------------------------------
  80.     def terminate
  81.         Graphics.freeze
  82.         dispose_all_windows
  83.         dispose_menu_layout
  84.         dispose_main_viewport
  85.     end
  86.     #--------------------------------------------------------------------------
  87.     # * Create Graphic Layout for Menu Screen
  88.     #--------------------------------------------------------------------------
  89.     def create_menu_layout
  90.         @menulay = Sprite.new
  91.         @menulay.bitmap = Bitmap.new(1, 1)
  92.         @menulay.z = 100
  93.         update_menu_layout
  94.     end
  95.     #--------------------------------------------------------------------------
  96.     # * Dispose Graphic Layout for Menu Screen
  97.     #--------------------------------------------------------------------------
  98.     def dispose_menu_layout
  99.         @menulay.dispose
  100.     end
  101.     #--------------------------------------------------------------------------
  102.     # * Update Graphic Layout for Menu Screen
  103.     #--------------------------------------------------------------------------    
  104.     def update_menu_layout; end
  105.     #--------------------------------------------------------------------------
  106.     # * Create Viewport
  107.     #--------------------------------------------------------------------------
  108.     def create_main_viewport
  109.         @viewport = Viewport.new(0, 0, 640, 480)
  110.         @viewport.z = 200
  111.     end
  112.     #--------------------------------------------------------------------------
  113.     # * Free Viewport
  114.     #--------------------------------------------------------------------------
  115.     def dispose_main_viewport
  116.         @viewport.dispose
  117.     end
  118.     #--------------------------------------------------------------------------
  119.     # * Update All Windows
  120.     #--------------------------------------------------------------------------
  121.     def update_all_windows
  122.         instance_variables.each do |varname|
  123.             ivar = instance_variable_get(varname)
  124.             ivar.update if ivar.is_a?(Window)
  125.         end
  126.     end
  127.     #--------------------------------------------------------------------------
  128.     # * Destroy All Windows
  129.     #--------------------------------------------------------------------------
  130.     def dispose_all_windows
  131.         instance_variables.each do |varname|
  132.             ivar = instance_variable_get(varname)
  133.             ivar.dispose if ivar.is_a?(Window)
  134.         end
  135.     end
  136.     #--------------------------------------------------------------------------
  137.     # * Fade Out All Sounds
  138.     #--------------------------------------------------------------------------
  139.     def fadeout_all(time = 1000)
  140.         $game_system.se_play($data_system.decision_se)
  141.         Audio.bgm_fade(time)
  142.         Audio.bgs_fade(time)
  143.         Audio.me_fade(time)
  144.     end
  145. end
Advertisement
Add Comment
Please, Sign In to add comment