Create Your Own Menu (part 4)

Engine : RPG Maker VX Ace

Click here for part 1
Click here for part 2
Click here for part 3

5. Creating Scene Menu

5a. Setup
Like before, insert a new script and name it Scene_Menu. Then paste this code below.

class Scene_Menu < Scene_MenuBase
  def start
    super
    create_window_menu_list
    create_window_actor_status
    create_window_location_gold
  end
  
  def create_window_menu_list    
  end
  
  def create_window_actor_status    
  end
  
  def create_window_location_gold
  end
end
Unlike other class, when created scene class will run the start method instead of initialize (you can see it in Scene_Base main method, that it will run start > post_start > then looping update).

5b. Creating Menu List
Paste this in def create_window_menu_list.

    @menulist_window = Window_MenuList.new

5c. Creating Windows Status
Paste this in def create_window_actor_status.

    #create array container for windows status
    @actor_status_windows = []
    #spacing between each windows
    spacing = 16
    #loop through each index for i = index in 0 until total actor in the party
    (0...$game_party.members.size).each do |i|
      #create status window
      @actor_status_windows[i] = Window_MenuStatus.new(i)  
      #set window's x position
      @actor_status_windows[i].x = 16 + i*(@actor_status_windows[i].width+spacing)
      #set window's y position
      @actor_status_windows[i].y = 64
    end
5d. Creating Location Gold Window
Paste this in def create_window_location_gold.

    @locgold_window = Window_LocGold.new

Now you can open the menu, and it should look like this
 But it's kinda plain isn't it? How about we animate the windows so it will look more, attractive?

5e. Animating the Windows.
I want the menu list and locgold window closed first, then it's open. To do that, we have to close the windows after we created it. Change def create_window_menu_list and def create_window_location_gold to this.

  def create_window_menu_list
    @menulist_window = Window_MenuList.new
    #set the window's openness, 0 is the minimum and 255 is the max
    @menulist_window.openness = 0
    #open the window
    @menulist_window.open
  end

  def create_window_location_gold
    @locgold_window = Window_LocGold.new
    #set the window's openness, 0 is the minimum and 255 is the max
    @locgold_window.openness = 0
    #open the window
    @locgold_window.open
  end
Now the menu should look like this,
But it's, still not enough. How about we animate the status windows too? Yeah let's do it.

5f. Animating Status Windows
I want the windows to move from outside to inside the screen with different speed. To do that, have to set the window's x outside the screen. Change def create_window_actor_status to this.

    #create array container for windows status
    @actor_status_windows = []
    #loop through each index for i = index in 0 until total actor in the party
    (0...$game_party.members.size).each do |i|
      #create status window
      @actor_status_windows[i] = Window_MenuStatus.new(i)  
      #set window's x position
      @actor_status_windows[i].x = -@actor_status_windows[i].width
      #set window's y position
      @actor_status_windows[i].y = 64
    end
Then, add this new method below.

  def update
    super
    #animate the windows status unless we done animating it
    animate_windows_status unless @status_animated
  end
  
  def animate_windows_status
    #array for containing the speed of each window
    @mv_speed ||= []
    #spacing between each windows
    spacing = 16
    #for checking if every windows is already in target_x
    ani_done = 0
    #for each window and index in @actor_status_window
    @actor_status_windows.each_with_index do |window, i|
      #set @mv_speed[index] to 2.0 if it's nil
      @mv_speed[i] ||= 3
      #x position that windows will moved to
      target_x = 16+i*(window.width+spacing)
      #if window's x is less than target_x
      if window.x < target_x
        #increment the window's x
        window.x += @mv_speed[i]
        #if after incremented the window's x is greater than target_x
        if window.x > target_x
          #set the window's x to target_x
          window.x = target_x
        end      
      end
      #if window's x equal to target_x
      if window.x == target_x
        #increase ani_done
        ani_done += 1
      end
      #increase the moving speed
      @mv_speed[i] += 1
    end
    #if ani_done equal to total number of windows
    if ani_done == @actor_status_windows.size
      #animated is done
      @status_animated = true
    end
  end
It should look like this.


But there's nothing happen if you select any command, because we didn't create the method for that yet.


0 komentar: