Hi, Im wondering how you can improve loading times.
On some machines my Custom Menu needs long to load. I think because it is so image heavy.
Maybe someone can give me a Tip where I could improve some of the code or maybe there are some other ways to display images:
Here is my Script:
I think the class that slow down the loading time is the class which starts at Line 352.
But Im not sure, maybe it have other reasons.
Thanks for every help here.
mfG
On some machines my Custom Menu needs long to load. I think because it is so image heavy.
Maybe someone can give me a Tip where I could improve some of the code or maybe there are some other ways to display images:
Here is my Script:
#==============================================================================# ▼ Tales of Vesperia CMS# -- Autor: eugene222# -- Version: 1.1# -- Date Last Updated: 29.09.2013# -- Date Created: 27.09.2013# -- Credits: eugene222, Valentine if you use his "status_bg.png"# # -- Note: Do not use the Icons included in the Demo, make your owns# I don't know who made these, so I cant give Credit. If somebody# know, please PM me.## I don't know who made the Background Picture. I have it from this # site: http://hdnaturepictures.com/anime-nature-wild-jungle.html## -- Thanks to: Reedo, who helped me with fixing some bug##==============================================================================# ▼ Changelog#==============================================================================# Version 1.1 : Fixed some bugs, and added the Option to use Custom Faces# Version 1.0a : Fixed a Bug when you Close the Window with no Layout Graphic# Version 1.0 : Created the Script#==============================================================================# ▼ Instructions#==============================================================================# To install this script, open up your script editor and copy/paste this script# to an open slot below ▼ Materials/素材 but above ▼ Main. Remember to save.## You need the following files in Graphics/Menu:## Icons:# item.png, skill.png equip.png, status.png formation.png, save.png, game_end.png# custom1-3.png if you use custom scenes and none.png ## Background:# menu_bg.jpg, menu.layout.png, status.png## See in the Demo how big the Pictures have to be.### Use the Config-Section below to Config the Mini-Icons and the Commands.## Only edit the the first three elements( enabled?, Name, Helptext)## For CustomCommands look below.##==============================================================================module Eugene222 module MConfig #--------------------------------------------------------------------------- # *CONFIG START* # # # *Configure Icon Index* #--------------------------------------------------------------------------- LocationIcon = 231 GoldIcon = 361 StepIcon = 467 BattleIcon = 131 TimeIcon = 280 #--------------------------------------------------------------------------- # *Do you want to use Custom Facesets?* # # Set to true if yes and to false if not # The Custom Faceset should be 100x188 # # The Facegraphic should be in the folder /Menu # The name should be: Actorname_face.png # eg.: "Eric_face.png" if the actors name is "Eric" #--------------------------------------------------------------------------- CustomFace = true #--------------------------------------------------------------------------- # *Default Menu Commands* #--------------------------------------------------------------------------- DC = { # Don't touch this line! #--------------------------------------------------------------------------- # Key enabled?, Name, Helptext #--------------------------------------------------------------------------- :item => [ true, "Item", "Choose items", :command_item], :skill => [ true, "Skill", "Choose skills", :command_personal], :equip => [ true, "Equipment", "Change equipment", :command_personal], :status => [ true, "Status", "View your status", :command_personal], :formation => [ true, "Formation", "Change formation", :command_formation], #--------------------------------------------------------------------------- # *Custom Menu Commands* # Key enabled?, Name, Helptext, :Symbol, Scene_Name # # # The Menu can handle 3 Custom Scenes. You have to set the Classname of # the Custom Scene after the Symbol. All custom Scenes have to be on top # of this Script. # # Example: # :custom1 => [ true, "Example", "Exampletext", # :custom_command, Scene_Example], # #--------------------------------------------------------------------------- :custom1 => [ true, "Questlog", "Exampletext", :custom_command, Scene_Item], :custom2 => [ false, "", "", :custom_command, ], :custom3 => [ false, "", "", :custom_command, ], #--------------------------------------------------------------------------- # *Save And Game_END Commands* #--------------------------------------------------------------------------- :save => [ true, "Speichern", "Save your progress", :command_save], :game_end => [ true, "Ende", "End the game", :command_game_end], #--------------------------------------------------------------------------- } # Don't touch this line! # # # *Config* END #--------------------------------------------------------------------------- endend#==============================================================================# ** new Window_Menu# methods: initialize, set_text, create_bg, draw_location, refresh, dispose,# dispose_icons, dispose_bg, dispose_bg1#==============================================================================class Window_Menu < Window_Help #----------------------------------------------------------------------------- include Eugene222::MConfig #----------------------------------------------------------------------------- # * initialize #----------------------------------------------------------------------------- def initialize(*args) super(*args) create_bg end #----------------------------------------------------------------------------- # * set_text #----------------------------------------------------------------------------- def set_text(line1, line2) unless line1 == @line1 @line1 = line1 @line2 = line2 refresh end end #----------------------------------------------------------------------------- # * create_bg #----------------------------------------------------------------------------- def create_bg @bg = Sprite.new @bg.bitmap = Cache.menu("menu_bg") rescue nil @bg1 = Sprite.new @bg1.bitmap = Cache.menu("menu_layout") rescue nil end #----------------------------------------------------------------------------- # * draw_location #----------------------------------------------------------------------------- def draw_location rect = Rect.new(contents.width/2,0, contents.width/2 - 26,line_height) contents.font.color = hp_gauge_color1 draw_text(rect,$game_map.display_name,2) draw_icon(LocationIcon, contents_width - 25, 0) unless $game_map.display_name == "" end #----------------------------------------------------------------------------- # * refresh #----------------------------------------------------------------------------- def refresh contents.clear contents.font.bold = true contents.font.color = system_color rect = Rect.new(0,0,contents.width/2, line_height) draw_text(rect,@line1) draw_location reset_font_settings rect = Rect.new(0,line_height, contents.width, line_height) draw_text(rect,@line2) end #----------------------------------------------------------------------------- # * dispose #----------------------------------------------------------------------------- def dispose super dispose_bg dispose_bg1 dispose_icons end #----------------------------------------------------------------------------- # * dispose_icons #----------------------------------------------------------------------------- def dispose_icons return unless @icon @icon.dispose end #----------------------------------------------------------------------------- # * dispose_bg #----------------------------------------------------------------------------- def dispose_bg return unless @bg @bg.bitmap.dispose if @bg.bitmap @bg.dispose end #----------------------------------------------------------------------------- # * dispose_bg1 #----------------------------------------------------------------------------- def dispose_bg1 return unless @bg1 @bg1.bitmap.dispose if @bg1.bitmap @bg1.dispose end #-----------------------------------------------------------------------------end#==============================================================================# ** Window_MenuCommand# new methods: init_commands, text#==============================================================================class Window_MenuCommand < Window_Command #----------------------------------------------------------------------------- include Eugene222::MConfig #----------------------------------------------------------------------------- # * initialize #----------------------------------------------------------------------------- def initialize(x,y) init_commands super(x,y) self.width = 24 + item_max * (48+spacing) self.height = 72 self.opacity = 0 select_last update end #----------------------------------------------------------------------------- # * Settings #----------------------------------------------------------------------------- def contents_width;(item_width + spacing) * item_max - spacing; end; def contents_height; 0; end; def item_height; 48; end; def col_max; item_max;; end; def spacing; 4; end; #----------------------------------------------------------------------------- # * make_command_list #----------------------------------------------------------------------------- def make_command_list DC.each do |k, v| case k when :save add_command(v[1], k, true,v[4]) if save_enabled when :formation add_command(v[1], k, true, v[4]) if formation_enabled else add_command(v[1], k, true,v[4]) if v[0] end end end #----------------------------------------------------------------------------- # * init_commands #----------------------------------------------------------------------------- def init_commands @commands = [] DC.each do |k,v| case k when :save @commands << k if save_enabled when :formation @commands << k if formation_enabled else @commands << k if v[0] end end end #----------------------------------------------------------------------------- # * draw_all_items #----------------------------------------------------------------------------- def draw_all_items @sprite_items = [] @commands.each_with_index do |command,index| icon = Cache.menu(command.to_s) rescue Cache.menu("none") sprite = Sprite.new sprite.bitmap = icon sprite.x = index * (48 + spacing) + self.x + 12 sprite.y = self.y + 12 sprite.z = self.z + 1 sprite.opacity = 155 @sprite_items << sprite end end #----------------------------------------------------------------------------- # * item_rect #----------------------------------------------------------------------------- def item_rect(index) rect = super rect.x = index * (48 + spacing) rect.y = 0 rect.width = 48 rect.height = 48 rect end #----------------------------------------------------------------------------- # * update #----------------------------------------------------------------------------- def update super unless @index == @s_index @s_index == @index @sprite_items.each {|sprite| sprite.opacity = 155} @sprite_items[@index].opacity = 255 end end #----------------------------------------------------------------------------- # * update_help #----------------------------------------------------------------------------- def update_help; @help_window.set_text(command_name(index),text(index)) end; #----------------------------------------------------------------------------- # * text #----------------------------------------------------------------------------- def text(index); DC[@list[index][:symbol]][2] end; #----------------------------------------------------------------------------- # * dispose #----------------------------------------------------------------------------- def dispose super return unless @sprite_items @sprite_items.each {|sprite| sprite.bitmap.dispose; sprite.dispose} @sprite_items = nil end #-----------------------------------------------------------------------------end#==============================================================================# ** new Window_NewMenuStatus# methods: initialize, [...], top_col=, calc_new_x ensure_cursor_visible, # item_rect, draw_item, draw_actor_simple_status, draw_actor_level, # draw_actor_exp, draw_layout, dispose#==============================================================================class Window_NewMenuStatus < Window_MenuStatus #----------------------------------------------------------------------------- attr_reader 😛ending_index #----------------------------------------------------------------------------- # * initialize #----------------------------------------------------------------------------- def initialize(x, y) @layout = [] @face = [] super(x, y) self.opacity = 0 self.ox = 0 @pending_index = -1 refresh end #----------------------------------------------------------------------------- # * settings #----------------------------------------------------------------------------- def window_width; Graphics.width; end; def window_height; Graphics.height - 72*2.5; end; def contents_width; (item_width + spacing) * item_max - spacing; end; def contents_height; item_height; end; def spacing; 24; end; def visible_line_number; 0; end; def item_height; height - standard_padding * 2; end; def col_max; 4; end; def top_col; ox / (item_width + spacing); end; #----------------------------------------------------------------------------- # * top_col= #----------------------------------------------------------------------------- def top_col=(col) col = 0 if col < 0 col = col_max - 1 if col > col_max - 1 self.ox = (index / col_max).ceil * (item_width + spacing) * col_max calc_new_x end #----------------------------------------------------------------------------- # * calc_new_x #----------------------------------------------------------------------------- def calc_new_x return if self.ox == @temp_ox @temp_ox = self.ox @layout.each do |layout| layout.ox = self.ox end @face.each do |face| face.ox = self.ox end end #----------------------------------------------------------------------------- # * ensure_cursor_visible #----------------------------------------------------------------------------- def ensure_cursor_visible self.top_col = ((index + 1) / col_max).floor * col_max end #----------------------------------------------------------------------------- # * item_rect #----------------------------------------------------------------------------- def item_rect(index) rect = super rect.x = index * (item_width + spacing) rect.y = 0 rect end #----------------------------------------------------------------------------- # * draw_item #----------------------------------------------------------------------------- def draw_item(index) draw_layout(index) actor = $game_party.members[index] enabled = $game_party.battle_members.include?(actor) rect = item_rect(index) draw_item_background(index) x = rect.x + (rect.width-96)/2 y = rect.y - 4 color = Color.new(0,0,0,140) color2 =Color.new(0,0,0,200) #Fill Rect behind Name contents.fill_rect(x-4, y + line_height / 3 + 4, 104, 22, color) #Make Border around Face contents.fill_rect(x-4, rect.y + line_height * 1 + 8, 104, 100, color2) contents.clear_rect(x-2, rect.y + line_height * 1 + 10, 100, 96) #Fill Rect behind the Gauges contents.fill_rect(x-4, y +line_height * 1.5 + 102, 104, 66, color) #Draw the things if Eugene222::MConfig::CustomFace draw_actor_custom_face(index, actor) else draw_actor_face(actor, x, rect.y + line_height * 1 + 10, enabled) end draw_actor_simple_status(actor, x , y) end #----------------------------------------------------------------------------- # * draw_actor_custom_face #----------------------------------------------------------------------------- def draw_actor_custom_face(index, actor) @face[index].dispose if @face[index] enabled = $game_party.battle_members.include?(actor) @face[index] = Sprite.new @face[index].bitmap = Cache.menu("#{actor.name}_face") rescue nil @face[index].x = index * (item_width + spacing) + 18 @face[index].ox = self.ox @face[index].opacity = enabled ? 255 : translucent_alpha @face[index].y = self.y + 1 / col_max * item_height + 22 @face[index].z = self.z - 1 end #----------------------------------------------------------------------------- # * draw_layout #----------------------------------------------------------------------------- def draw_layout(index) @layout[index].dispose if @layout[index] @layout[index] = Sprite.new @layout[index].bitmap = Cache.menu("status_bg") rescue nil @layout[index].ox = self.ox @layout[index].x = index * (item_width + spacing) + 4 @layout[index].y = self.y + 1 / col_max * item_height + 4 @layout[index].z = self.z - 3 end #----------------------------------------------------------------------------- # * draw_actor_simple_status #----------------------------------------------------------------------------- def draw_actor_simple_status(actor, x, y) draw_actor_name(actor, x-2, y + line_height / 3 +4, 102) draw_actor_icons(actor, x, y + line_height* 1.5 + 104, 96) contents.font.size = 20 draw_actor_hp(actor, x-2, y + line_height * 2.5 + 102, 100) draw_actor_mp(actor, x-2, y + line_height * 3.25 + 102, 100) draw_actor_exp(actor,x-2, y + line_height * 1.0 + 90, 100) end #----------------------------------------------------------------------------- # * draw_actor_level #----------------------------------------------------------------------------- def draw_actor_level(actor, x, y) change_color(system_color) draw_text(x, y, 24, line_height, Vocab::level_a) change_color(normal_color) draw_text(x + 24, y, 16, line_height, actor.level, 2) end #----------------------------------------------------------------------------- # * draw_current_and_max_values #----------------------------------------------------------------------------- def draw_current_and_max_values(x, y, width, current, max, color1, color2) change_color(color1) xr = x + width draw_text(xr - 84, y, 42, line_height, current, 2) change_color(color2) draw_text(xr - 46, y, 12, line_height, "/", 2) draw_text(xr - 42, y, 42, line_height, max, 2) end #----------------------------------------------------------------------------- # * draw_actor_exp #----------------------------------------------------------------------------- def draw_actor_exp(actor, x, y, width = 124) exp_now = actor.exp-actor.current_level_exp exp_need = actor.next_level_exp.to_f-actor.current_level_exp exp = (exp_now.to_f/100)/(exp_need.to_f/100) unless actor.max_level? exp_rate = exp exp_text = "#{(exp*100).to_i}%" else exp_rate = 1 exp_text = "MAX" end draw_gauge(x, y, width, exp_rate, tp_gauge_color1, tp_gauge_color2) draw_actor_level(actor, x, y) draw_text(x + width - 42, y, 42, line_height, exp_text , 2) end #----------------------------------------------------------------------------- # * draw_gauge #----------------------------------------------------------------------------- def draw_gauge(x, y, width, rate, color1, color2) fill_w = (width * rate).to_i gauge_y = y + line_height - 8 contents.fill_rect(x, gauge_y, width, 4, gauge_back_color) contents.gradient_fill_rect(x, gauge_y, fill_w, 4, color1, color2) end #----------------------------------------------------------------------------- # * dispose #----------------------------------------------------------------------------- def dispose super dispose_face dispose_layout end #----------------------------------------------------------------------------- # * dispose_layout #----------------------------------------------------------------------------- def dispose_layout return unless @layout @layout.each do |layout| layout.bitmap.dispose if layout.bitmap.dispose layout.dispose end @layout = nil end #----------------------------------------------------------------------------- # * dispose_face #----------------------------------------------------------------------------- def dispose_face return unless @face @face.each do |face| face.bitmap.dispose if face.bitmap face.dispose end @face = nil end #-----------------------------------------------------------------------------end#==============================================================================# ** new Window_Information# methods: initialize, draw_gold, draw_steps, draw_battle_won, draw_time,# update#==============================================================================class Window_Information < Window_Base #----------------------------------------------------------------------------- include Eugene222::MConfig #----------------------------------------------------------------------------- # * initialize #----------------------------------------------------------------------------- def initialize super(0,Graphics.height-72,Graphics.width, 72) self.opacity = 0 update end #----------------------------------------------------------------------------- # * draw_gold #----------------------------------------------------------------------------- def draw_gold draw_text(0, 12, contents_width/4 - 46, line_height, $game_party.gold, 2) draw_icon(GoldIcon, contents_width/4 - 45, 12) end #----------------------------------------------------------------------------- # * draw_steps #----------------------------------------------------------------------------- def draw_steps draw_text(contents_width/4, 12, contents_width/4-46, line_height, $game_party.steps, 2) draw_icon(StepIcon, contents_width*2/4 - 45, 12) end #----------------------------------------------------------------------------- # * draw_battle_won #----------------------------------------------------------------------------- def draw_battle_won draw_text(contents_width*2/4, 12, contents_width/4-46, line_height, $game_system.battle_won_count, 2) draw_icon(BattleIcon, contents_width*3/4 - 45, 12) end #----------------------------------------------------------------------------- # * draw_time #----------------------------------------------------------------------------- def draw_time draw_text(contents_width*3/4, 12, contents_width/4-26, line_height, $game_system.playtime_s, 2) draw_icon(TimeIcon, contents_width - 25, 12) end #----------------------------------------------------------------------------- # * update #----------------------------------------------------------------------------- def update super contents.clear draw_gold draw_steps draw_battle_won draw_time end #-----------------------------------------------------------------------------end#==============================================================================# ** Scene_Menu# new_methods: create_information_window, custom_command#==============================================================================class Scene_Menu < Scene_MenuBase #----------------------------------------------------------------------------- # * start #----------------------------------------------------------------------------- def start super @info = Eugene222::MConfig:😀C @help_window = Window_Menu.new(2) @help_window.opacity = 0 create_command_window create_status_window create_information_window end #----------------------------------------------------------------------------- # * create_command_window #----------------------------------------------------------------------------- def create_command_window @command_window = Window_MenuCommand.new(0,@help_window.height-12) @command_window.help_window = @help_window @info.each do |k,v| @command_window.set_handler(k, method(v[3])) if v[0] end @command_window.set_handler🙂cancel, method🙂return_scene)) end #----------------------------------------------------------------------------- # * create_information_window #----------------------------------------------------------------------------- def create_information_window @information_window = Window_Information.new end #----------------------------------------------------------------------------- # * create_status_window #----------------------------------------------------------------------------- def create_status_window @status_window = Window_NewMenuStatus.new(0, @command_window.height*2 - 24 ) end #----------------------------------------------------------------------------- # * custom_command #----------------------------------------------------------------------------- def custom_command SceneManager.call(@command_window.current_ext) end #-----------------------------------------------------------------------------end#==============================================================================# ** Cache# new method: self.menu#==============================================================================module Cache #----------------------------------------------------------------------------- # * self.menu #----------------------------------------------------------------------------- def self.menu(filename) load_bitmap("Graphics/Menu/", filename) end #-----------------------------------------------------------------------------end#==============================================================================# ** BattleManager# alias Method: self.process_victory#==============================================================================module BattleManager class << self alias eugene222_process_vicotory process_victory #--------------------------------------------------------------------------- # * self.process_victory #--------------------------------------------------------------------------- def process_victory $game_system.battle_won_count += 1 eugene222_process_vicotory end end #-----------------------------------------------------------------------------end#==============================================================================# ** Game_System# alias Method: initialize# new attr_accessor: battle_won_count#==============================================================================class Game_System #----------------------------------------------------------------------------- attr_accessor :battle_won_count #----------------------------------------------------------------------------- alias eugene222_game_system_initialize initialize #----------------------------------------------------------------------------- # * initialize #----------------------------------------------------------------------------- def initialize @battle_won_count = 0 eugene222_game_system_initialize end #-----------------------------------------------------------------------------end#===============================================================================#-------------------------------------------------------------------------------# ** SCRIPT END **#-------------------------------------------------------------------------------#===============================================================================
But Im not sure, maybe it have other reasons.
Thanks for every help here.
mfG
