Este script permite que você use barras com gradientes em qualquer lugar do seu jogo do RPG Maker XP. Estas também estão animadase também vão diminuir ou aumentar suavemente o seu valor. Este script vem com barras Hp/Sp/Exp para scripters e um modelo para a criação de um sprite gradiente para scripters. As barras Hp/Sp/Exp são configuráveis.
O script Animated Gradient Bars
foi feito por Trickster e ele usa o RMXP Standard Development Kit e o Method and Class Library, de sua autoria também. O minigame/demo já tem todos estes scripts e os outros necessários para conseguir o efeito desejado. Ele usa uma batalha para ilustrar também.
#-------------------------------------------------------------------------- # ● Begin SDK Enabled Check #-------------------------------------------------------------------------- if SDK.state('Animated Gradient Bars') == true class Sprite_ActorHpBar < Sprite_GradientBar #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(actor, x, y, width, height) # Get Actor Viewport if in scene battle else nil viewport = $game_temp.in_battle ? $scene.spriteset.viewport2 : nil # Call Sprite_GradientBar#initialize super(x, y, width, height, 1, 1, 1, viewport) # Setup Borders self.bx = Gradient_Bars_Setup::Border_Dim self.by = Gradient_Bars_Setup::Border_Dim # Setup Instance Variables @actor = actor @last = @actor.hp @speed = Gradient_Bars_Setup::Update_Speed @rate = nil @update_count = 0 # Setup Background Borders self.background.bx = Gradient_Bars_Setup::Background_Dim self.background.by = Gradient_Bars_Setup::Background_Dim # Refresh Boarder to Suit New Border self.background.refresh # If Slanted Mode if Gradient_Bars_Setup::Slanted_Bars # Draw A Slanted Background draw_slanted_background end # Get Gradient File @file = Gradient_Bars_Setup::Hp_Bar_Graphic # Set Blending to Addition self.blend_type = 1 # Setup Florish if Conditions are correct if not [0,1].include?(Gradient_Bars_Setup::Hp_Flourish.size) # Setup Change Rate Array @change_rate = [] # Current Index is zero @current_flourish = 0 # Get RGB Array from color rgb = Gradient_Bars_Setup::Hp_Flourish[0].to_rgb # Set Red, Green, and Blue self.color.red, self.color.green, self.color.blue = *rgb # Setup Alpha for Blending self.color.alpha = Gradient_Bars_Setup::Hp_Flourish_Alpha # Setup Flourishing setup_flourish end # Refresh Sprite refresh end #-------------------------------------------------------------------------- # * Setup "Flourishing" #-------------------------------------------------------------------------- def setup_flourish # Get RGB Array from color rgb = Gradient_Bars_Setup::Hp_Flourish[@current_flourish].to_rgb # Set Red, Green, and Blue self.color.red, self.color.green, self.color.blue = *rgb # Get HSB Array from color hsb = self.color.to_hsb # Get Next Color to move to next_flourish = (@current_flourish + 1) % Gradient_Bars_Setup::Hp_Flourish.size # Get HSB Array from next color next_hsb = Gradient_Bars_Setup::Hp_Flourish[next_flourish].to_hsb # Get Rate of Change (Speed) rate = Gradient_Bars_Setup::Hp_Flourish_Speed # Clear Change Rate @change_rate.clear # Reset Count @count_flourish = rate # Set Values for Change Rate 3.times {|i| @change_rate[i] = (next_hsb[i] - hsb[i]) / rate} end #-------------------------------------------------------------------------- # * Start Animation #-------------------------------------------------------------------------- def start @update_count = Gradient_Bars_Setup::Update_Delay end #-------------------------------------------------------------------------- # * Update #-------------------------------------------------------------------------- def update # Call Sprite_GradientBar's update method # which in turn only calls Sprite's update method super # Increase frame counter @count += 1 # Decrease Update Counter @update_count -= 1 if @update_count > 0 # Update Flourish if Conditions are right update_flourish if @change_rate != nil # Skip update if no speed or speed frames have not passed or in battle return if @speed == 0 or @count % @speed != 0 # Update Bars update_bars end #-------------------------------------------------------------------------- # * Update "Flourishing" #-------------------------------------------------------------------------- def update_flourish # Update Hue, Saturation, and Value self.color.hue += @change_rate[0] self.color.saturation += @change_rate[1] self.color.value += @change_rate[2] # Decrease Count and if Zero Setup new Flourish @count_flourish -= 1 if @count_flourish == 0 @current_flourish += 1 @current_flourish %= Gradient_Bars_Setup::Hp_Flourish.size setup_flourish end end #-------------------------------------------------------------------------- # * Update Bars, Decrease Contents Steadily #-------------------------------------------------------------------------- def update_bars return if not self.updatable? # If Update Rate is nil then increment by current - last / time * +-1 if Gradient_Bars_Setup::Update_Rate == nil # Get Rate @rate = (@actor.hp - @last) / Gradient_Bars_Setup::Update_Time.to_f # Increase By Rate @last += @rate else # Increment Last By + 1 or -1 times Update Rate (move to current hp) @last += (@actor.hp - @last).sign * Gradient_Bars_Setup::Update_Rate end # Restrict last to actor.hp, actor.maxhp if decreasing @last = [[@last, @actor.hp].max, @actor.maxhp].min if @last > @actor.hp # Restrict last to 0, actor.hp if increasing @last = [[@last, 0].max, @actor.hp].min if @last < @actor.hp # Refresh the bar refresh end #-------------------------------------------------------------------------- # * Updatable? #-------------------------------------------------------------------------- def updatable? return @last != @actor.hp && @update_count <= 0 && @actor.damage == nil end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh # Redraw Bar self.bitmap.clear # Arguments border = Gradient_Bars_Setup::Border arguments = 0,0,@last,@actor.maxhp,@file,@width,@height,border,bx,by # If Slanted Mode if Gradient_Bars_Setup::Slanted_Bars self.bitmap.draw_trick_gradient_bar_sub_slant(*arguments) else self.bitmap.draw_trick_gradient_bar_sub(*arguments) end # If Color Change Process given if Gradient_Bars_Setup::Hp_Color_Proc != nil # Prevent Division by Zero percent = @actor.maxhp != 0 ? @last.to_f/@actor.maxhp : 0 # Call Proc and send the percent to get color values color = Gradient_Bars_Setup::Hp_Color_Proc.call(percent) # Argument expansion on returned array if color.size == 3 self.color.red, self.color.green, self.color.blue = *color else self.color.red, self.color.green, self.color.blue, self.color.alpha = *color end end end end class Sprite_ActorSpBar < Sprite_GradientBar #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(actor, x, y, width, height) # Get Actor Viewport if in scene battle else nil viewport = $game_temp.in_battle ? $scene.spriteset.viewport2 : nil # Call Sprite_GradientBar#initialize super(x, y, width, height, 1, 1, 1, viewport) # Setup Borders self.bx = Gradient_Bars_Setup::Border_Dim self.by = Gradient_Bars_Setup::Border_Dim # Setup Instance Variables @actor = actor @last = @actor.sp @speed = Gradient_Bars_Setup::Update_Speed @rate = nil @update_count = 0 # Setup Background Borders self.background.bx = Gradient_Bars_Setup::Background_Dim self.background.by = Gradient_Bars_Setup::Background_Dim # Refresh Boarder to Suit New Border self.background.refresh # If Slanted Mode if Gradient_Bars_Setup::Slanted_Bars # Draw A Slanted Background draw_slanted_background end # Get Gradient File @file = Gradient_Bars_Setup::Sp_Bar_Graphic # Set Blending to Addition self.blend_type = 1 # Setup Florish if Conditions are correct if not [0,1].include?(Gradient_Bars_Setup::Sp_Flourish.size) # Setup Change Rate Array @change_rate = [] # Current Index is zero @current_flourish = 0 # Get RGB Array from color rgb = Gradient_Bars_Setup::Sp_Flourish[0].to_rgb # Set Red, Green, and Blue self.color.red, self.color.green, self.color.blue = *rgb # Setup Alpha for Blending self.color.alpha = Gradient_Bars_Setup::Sp_Flourish_Alpha # Setup Flourishing setup_flourish end # Refresh Sprite refresh end #-------------------------------------------------------------------------- # * Setup "Flourishing" #-------------------------------------------------------------------------- def setup_flourish # Get RGB Array from color rgb = Gradient_Bars_Setup::Sp_Flourish[@current_flourish].to_rgb # Set Red, Green, and Blue self.color.red, self.color.green, self.color.blue = *rgb # Get HSB Array from color hsb = self.color.to_hsb # Get Next Color to move to next_flourish = (@current_flourish + 1) % Gradient_Bars_Setup::Sp_Flourish.size # Get HSB Array from next color next_hsb = Gradient_Bars_Setup::Sp_Flourish[next_flourish].to_hsb # Get Rate of Change (Speed) rate = Gradient_Bars_Setup::Sp_Flourish_Speed # Clear Change Rate @change_rate.clear # Reset Count @count_flourish = rate # Set Values for Change Rate 3.times {|i| @change_rate[i] = (next_hsb[i] - hsb[i]) / rate} end #-------------------------------------------------------------------------- # * Start Animation #-------------------------------------------------------------------------- def start @update_count = Gradient_Bars_Setup::Update_Delay end #-------------------------------------------------------------------------- # * Update #-------------------------------------------------------------------------- def update # Call Sprite_GradientBar's update method # which in turn only calls Sprite's update method super # Increase frame counter @count += 1 # Decrease Update Counter @update_count -= 1 if @update_count > 0 # Update Flourish if Conditions are right update_flourish if @change_rate != nil # Skip update if no speed or speed frames have not passed return if @speed == 0 or @count % @speed != 0 # Update Bars update_bars end #-------------------------------------------------------------------------- # * Update "Flourishing" #-------------------------------------------------------------------------- def update_flourish # Update Hue, Saturation, and Value self.color.hue += @change_rate[0] self.color.saturation += @change_rate[1] self.color.value += @change_rate[2] # Decrease Count and if Zero Setup new Flourish @count_flourish -= 1 if @count_flourish == 0 @current_flourish += 1 @current_flourish %= Gradient_Bars_Setup::Sp_Flourish.size setup_flourish end end #-------------------------------------------------------------------------- # * Update Bars, Decrease Contents Steadily #-------------------------------------------------------------------------- def update_bars return if not self.updatable? # If Update Rate is nil then increment by current - last / time * +-1 if Gradient_Bars_Setup::Update_Rate == nil # Get Rate @rate = (@actor.sp - @last) / Gradient_Bars_Setup::Update_Time.to_f # Increase By Rate @last += @rate else # Increment Last By + 1 or -1 times Update Rate (move to current sp) @last += (@actor.sp - @last).sign * Gradient_Bars_Setup::Update_Rate end # Restrict last to actor.sp, actor.maxsp if decreasing @last = [[@last, @actor.sp].max, @actor.maxsp].min if @last > @actor.sp # Restrict last to 0, actor.sp if increasing @last = [[@last, 0].max, @actor.sp].min if @last < @actor.sp # Refresh the bar refresh end #-------------------------------------------------------------------------- # * Updatable? #-------------------------------------------------------------------------- def updatable? return @last != @actor.sp && @update_count <= 0 end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh # Redraw Bar self.bitmap.clear # Arguments border = Gradient_Bars_Setup::Border arguments = 0,0,@last,@actor.maxsp,@file,@width,@height,border,bx,by # If Slanted Mode if Gradient_Bars_Setup::Slanted_Bars self.bitmap.draw_trick_gradient_bar_sub_slant(*arguments) else self.bitmap.draw_trick_gradient_bar_sub(*arguments) end # If Color Change Process given if Gradient_Bars_Setup::Sp_Color_Proc != nil # Prevent Division by Zero percent = @actor.maxhp != 0 ? @last.to_f/@actor.maxhp : 0 # Call Proc and send the percent to get color values color = Gradient_Bars_Setup::Sp_Color_Proc.call(percent) # Argument expansion on returned array if color.size == 3 self.color.red, self.color.green, self.color.blue = *color else self.color.red, self.color.green, self.color.blue, self.color.alpha = *color end end end end class Sprite_ActorExpBar < Sprite_GradientBar #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(actor, x, y, width, height) # Get Actor Viewport if in scene battle else nil viewport = $game_temp.in_battle ? $scene.spriteset.viewport2 : nil # Call Sprite_GradientBar#initialize super(x, y, width, height, 1, 1, 1, viewport) # Setup Borders self.bx = Gradient_Bars_Setup::Border_Dim self.by = Gradient_Bars_Setup::Border_Dim # Setup Instance Variables @actor = actor @last = @actor.now_exp @speed = Gradient_Bars_Setup::Update_Speed @rate = nil @update_count = 0 # Setup Background Borders self.background.bx = Gradient_Bars_Setup::Background_Dim self.background.by = Gradient_Bars_Setup::Background_Dim # Refresh Boarder to Suit New Border self.background.refresh # If Slanted Mode if Gradient_Bars_Setup::Slanted_Bars # Draw A Slanted Background draw_slanted_background end # Get Gradient File @file = Gradient_Bars_Setup::Exp_Bar_Graphic # Set Blending to Addition self.blend_type = 1 # Setup Florish if Conditions are correct if not [0,1].include?(Gradient_Bars_Setup::Exp_Flourish.size) # Setup Change Rate Array @change_rate = [] # Current Index is zero @current_flourish = 0 # Get RGB Array from color rgb = Gradient_Bars_Setup::Exp_Flourish[0].to_rgb # Set Red, Green, and Blue self.color.red, self.color.green, self.color.blue = *rgb # Setup Alpha for Blending self.color.alpha = Gradient_Bars_Setup::Exp_Flourish_Alpha # Setup Flourishing setup_flourish end # Refresh Sprite refresh end #-------------------------------------------------------------------------- # * Setup "Flourishing" #-------------------------------------------------------------------------- def setup_flourish # Get RGB Array from color rgb = Gradient_Bars_Setup::Exp_Flourish[@current_flourish].to_rgb # Set Red, Green, and Blue self.color.red, self.color.green, self.color.blue = *rgb # Get HSB Array from color hsb = self.color.to_hsb # Get Next Color to move to next_flourish = (@current_flourish + 1) % Gradient_Bars_Setup::Exp_Flourish.size # Get HSB Array from next color next_hsb = Gradient_Bars_Setup::Exp_Flourish[next_flourish].to_hsb # Get Rate of Change (Speed) rate = Gradient_Bars_Setup::Exp_Flourish_Speed # Clear Change Rate @change_rate.clear # Reset Count @count_flourish = rate # Set Values for Change Rate 3.times {|i| @change_rate[i] = (next_hsb[i] - hsb[i]) / rate} end #-------------------------------------------------------------------------- # * Start Animation #-------------------------------------------------------------------------- def start @update_count = Gradient_Bars_Setup::Update_Delay end #-------------------------------------------------------------------------- # * Update #-------------------------------------------------------------------------- def update # Call Sprite_GradientBar's update method # which in turn only calls Sprite's update method super # Increase frame counter @count += 1 # Decrease Update Counter @update_count -= 1 if @update_count > 0 # Update Flourish if Conditions are right update_flourish if @change_rate != nil # Skip update if no speed or speed frames have not passed return if @speed == 0 or @count % @speed != 0 # Update Bars update_bars end #-------------------------------------------------------------------------- # * Update "Flourishing" #-------------------------------------------------------------------------- def update_flourish # Update Hue, Saturation, and Value self.color.hue += @change_rate[0] self.color.saturation += @change_rate[1] self.color.value += @change_rate[2] # Decrease Count and if Zero Setup new Flourish @count_flourish -= 1 if @count_flourish == 0 @current_flourish += 1 @current_flourish %= Gradient_Bars_Setup::Exp_Flourish.size setup_flourish end end #-------------------------------------------------------------------------- # * Update Bars, Decrease Contents Steadily #-------------------------------------------------------------------------- def update_bars return if not self.updatable? # If Update Rate is nil then increment by current - last / time * +-1 if Gradient_Bars_Setup::Update_Rate == nil # Get Rate @rate = (@actor.now_exp - @last) / Gradient_Bars_Setup::Update_Time.to_f # Increase By Rate @last += @rate else # Increment Last By + 1 or -1 times Update Rate (move to current exp) @last += (@actor.now_exp - @last).sign * Gradient_Bars_Setup::Update_Rate end # Restrict last to actor.now_exp, actor.next_exp if decreasing @last = [[@last, @actor.now_exp].max, @actor.next_exp].min if @last > @actor.now_exp # Restrict last to 0, actor.now_exp if increasing @last = [[@last, 0].max, @actor.now_exp].min if @last < @actor.now_exp # Refresh the bar refresh end #-------------------------------------------------------------------------- # * Updatable? #-------------------------------------------------------------------------- def updatable? return @last != @actor.now_exp && @update_count <= 0 end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh self.bitmap.clear # Arguments border = Gradient_Bars_Setup::Border arguments = 0,0,@last,@actor.next_exp,@file,@width,@height,border,bx,by # If Slanted Mode if Gradient_Bars_Setup::Slanted_Bars self.bitmap.draw_trick_gradient_bar_sub_slant(*arguments) else self.bitmap.draw_trick_gradient_bar_sub(*arguments) end # If Color Change Process given if Gradient_Bars_Setup::Exp_Color_Proc != nil # Prevent Division by Zero percent = @actor.next_exp != 0 ? @last.to_f/@actor.next_exp : 0 # Call Proc and send the percent to get color values color = Gradient_Bars_Setup::Exp_Color_Proc.call(percent) # Argument expansion on returned array if color.size == 3 self.color.red, self.color.green, self.color.blue = *color else self.color.red, self.color.green, self.color.blue, self.color.alpha = *color end end end end #-------------------------------------------------------------------------- # End SDK Enabled Check #-------------------------------------------------------------------------- end # Begin Bar Template Class (General) # Change stuff in <> (remove the <> as well) =begin class Sprite_<Name>Bar < Sprite_GradientBar #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(x, y, width, height) super(x, y, width, height) # Initialize Last @last = <variable min> # Setup Bar update speed @speed = <update speed> # Setup Borders self.bx = <border> self.by = <border> # Setup Background Borders self.background.bx = <background border> self.background.by = <background border> # Refresh Border to Suit New Border self.background.refresh # Get Gradient File @file = <gradient file you wish to use> # Refresh Sprite refresh end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update # Call Sprite_GradientBar's update method # which in turn only calls Sprite's update method super # Increase frame count @count += 1 # Skip if 0 speed or speed frames have not passed return if @speed == 0 or @count % @speed != 0 # If Sp Changed if @last != <variable min> # Increment Last By + 1 or -1 times Update Rate (move to current hp) @last += (<variable min> - @last).sign * <update rate> # Refresh the bar refresh end end #-------------------------------------------------------------------------- # * Updatable? #-------------------------------------------------------------------------- def updatable? return @last != <variable min> end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh self.bitmap.clear self.bitmap.draw_trick_gradient_bar_sub(0,0,@last,<variable max>,@file,@width, @height,<background file>,bx,by) end end =end
Observação: se você gostou deste post ou ele lhe foi útil de alguma forma, por favor considere apoiar financeiramente a Gaming Room. Fico feliz só de ajudar, mas a contribuição do visitante é muito importante para que este site continua existindo e para que eu possa continuar provendo este tipo de conteúdo e melhorar cada vez mais. Acesse aqui e saiba como. Obrigado!