Create Your Own Menu (part 2)
Engine : RPG Maker VX Ace
Click here for part 1
Insert a new script under Window_MenuList, change the name to Window_MenuStatus.
Everything is explained in the code.
Now, let's test it. The step is like the previous part, but change the script call to:
You should see the window status of actor 1
Click here for part 3
Click here for part 1
3. Creating Actor Status Window
3a. SetupInsert a new script under Window_MenuList, change the name to Window_MenuStatus.
3b. Create Window_MenuStatus class
Paste this code below in Window_MenuStatus
class Window_MenuStatus < Window_Selectable #Index is actor index, used for determining the actor and #window's position def initialize(index) #Window properties #super(x, y, width, height) super(0, 0, 116, 288) #save index to local variable @index = index #make a pointer to the actor @actor = $game_party.members[@index] #refresh the window contents refresh end def item_max 1 end def item_height height - standard_padding * 2 end def refresh #clear the contents contents.clear #return unless actor isn't nil return unless @actor draw_actor_name draw_actor_level draw_actor_sprite draw_actor_face draw_actor_parameter end def draw_actor_name #draw_text(x, y, width, height, text, align (default value is 0)) #align : # 0 = Left # 1 = Center # 2 = Right #set the text height to font size, which is 24 for default draw_text(0, 0, contents.width, 24, @actor.name, 1) end def draw_actor_level #change the font size of contents to 16 contents.font.size = 16 #change the font color #change_color(color, enabled? (default value is true)) #text_color(n) is to get the color of n index in window graphic #the same as \C[n] in Event message change_color(text_color(16)) #Vocab::level_a is the term for level (short) that can be changed in #database. #If there is #{} in double string (""), it will run the command in that #bracket and combine the result. #"#{Vocab::level_a} : #{@actor.level}" is the same thing as : # Vocab::level_a + " : " + @actor.level.to_s draw_text(0, 24, contents.width, 16, "#{Vocab::level_a} : #{@actor.level}", 1) end def draw_actor_sprite #draw_character(character name, character index, x, y) draw_character(@actor.character_name, @actor.character_index, contents.width/2, 76) end def draw_actor_face #draw_face(face_name, face_index, x, y, enabled? (default value is true)) draw_face(@actor.face_name, @actor.face_index, (contents.width-96)/2, 82, true) #(contents.width-96)/2 is for calculating the center point. 96 is the width of face graphic. end def draw_actor_parameter contents.font.size = 16 change_color(text_color(0)) #draw hp text draw_text(0, 182, contents.width, 16, "#{@actor.hp} / #{@actor.mhp}") #draw hp gauge #draw_gauge(x, y, width, rate, color1, color2) draw_gauge(0, 182, contents.width, @actor.hp_rate, text_color(20), text_color(21)) #draw mp text draw_text(0, 208, contents.width, 16, "#{@actor.mp} / #{@actor.mmp}") #draw mp gauge draw_gauge(0, 208, contents.width, @actor.mp_rate, text_color(22), text_color(23)) #for calculating the percentage of experience. One variable has to be #converted to float(.to_f). exp_rate = @actor.exp / (@actor.next_level_exp - @actor.exp).to_f #draw exp text draw_text(0, 238, contents.width, 16, "#{@actor.exp} / #{@actor.next_level_exp - @actor.exp}") #draw exp gauge draw_gauge(0, 238, contents.width, exp_rate, text_color(28), text_color(29)) end end
Now, let's test it. The step is like the previous part, but change the script call to:
You should see the window status of actor 1
Click here for part 3
0 komentar: