Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

How can I replace draw_bar with show_image?

This portion of Raziel's HUD script causes a lot of lag when updated. Before using this HUD, I used an evented HUD using pictures of bars that stretched and shrunk depending on health amount. This suprisingly, lagged less than this portion of the script, despite it having taken up over 30 common events.

I am wondering if this script can be altered to replace the bars with the images of bars I used previously, and if so, how can this be done? Thank you for your time!

Code:
      width = 100
      height = 10
      draw_slant_bar(x + 403, 38, actor.hp, actor.maxhp, width, height, Color.new(24, 248, 74, 255), Color.new(224, 254, 214, 255))
      draw_slant_bar(x + 403, 188, actor.sp, actor.maxsp, width, height, Color.new(228, 211, 118, 255), Color.new(250, 247, 226, 255))
      unless actor.level == 99
        draw_slant_bar(x + 403, 338, actor.now_exp, actor.next_exp, width, height, Color.new(174, 174, 255, 255), Color.new(230, 230, 255, 255))
      else
        draw_slant_bar(x + 8, 436, 1, 1, width = 100, height = 10, Color.new(0, 150, 0), Color.new(60, 255, 60))
      end


Full Code:

Code:
class Scene_Map
  
  SWITCH_ID = 57
  $center_hud = true
  
  alias raz_hud_main main
  alias raz_hud_update update
  
  def main
    @size = $game_party.actors.size
    raz_hud_main
    @hud_window.dispose
    for i in 0...$game_party.actors.size
      @hud_dummy[i].dispose
    end
  end
  
  def update
    if @size != $game_party.actors.size
      @hud_window.refresh
      show_window
    end
    if @hud != true
      main_window
    end
    turn_hud_on_off
    @hud_window.update
    raz_hud_update
  end
  
  def show_window
    @size = $game_party.actors.size
    for i in 0..3
      @hud_dummy[i].visible = ($game_party.actors[i] != nil)
    end
  end
  
  def main_window
    @opacity = 200
    @hud_dummy = []
    for i in 0...4
      if $center_hud == true
      @hud_dummy[0] = Window_Base.new(1, 468,505, 11)
      @hud_dummy[1] = Window_Base.new(1, 456,505, 11)
      @hud_dummy[2] = Window_Base.new(1, 444,505, 11)
      @hud_dummy[3] = Window_Base.new(0, 0,0, 0)
      end
      @hud_dummy[i].opacity = @opacity
      @hud_dummy[i].visible = false
    end
    @hud_window = Window_HUD.new
    for i in 0...$game_party.actors.size
      @hud_dummy[i].visible = $game_party.actors[i] != nil
    end
    @hud = true
  end
  
def turn_hud_on_off
 if $game_switches[SWITCH_ID] == false
  @hud_window.visible = false
    for i in 0...$game_party.actors.size
      @hud_dummy[i].visible = false
    end
  end
  
  
  if $game_switches[SWITCH_ID] == true
    @hud_window.visible = true
    for i in 0...$game_party.actors.size
      @hud_dummy[i].visible = true
    end
  end
end

end

  
class Window_HUD < Window_Base
  def initialize
    super(-12, 0, 800, 600)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      eval("@old_hp#{i+1} = actor.hp; @old_sp#{i+1} = actor.sp; @old_exp#{i+1} = actor.now_exp")
    end
    refresh
  end
  
  def refresh
    self.contents.clear
    for i in 0...$game_party.actors.size
      a = $game_party.actors.size - 1
      actor = $game_party.actors[i]
      if $center_hud == true
      x = 49 + i * -12
    else
      x = i * 12 + 25
      end
      self.contents.font.size = 12
      width = 100
      height = 10
      draw_slant_bar(x + 403, 38, actor.hp, actor.maxhp, width, height, Color.new(24, 248, 74, 255), Color.new(224, 254, 214, 255))
      draw_slant_bar(x + 403, 188, actor.sp, actor.maxsp, width, height, Color.new(228, 211, 118, 255), Color.new(250, 247, 226, 255))
      unless actor.level == 99
        draw_slant_bar(x + 403, 338, actor.now_exp, actor.next_exp, width, height, Color.new(174, 174, 255, 255), Color.new(230, 230, 255, 255))
      else
        draw_slant_bar(x + 8, 436, 1, 1, width = 100, height = 10, Color.new(0, 150, 0), Color.new(60, 255, 60))
      end
      actor = $game_party.actors[i]
      x = 5
      y = i * -12 + 66
      self.contents.blt(x + -5, y + 386,RPG::Cache.picture(actor.character_name + "hud"), Rect.new(0,0,180,120))
      x = 5
      y = i * -12 + 444
      self.contents.font.color = normal_color
      draw_actor_name(actor, x + 7, y - 2)
      self.contents.font.size = 12
      draw_actor_state(actor, x + 458, y - 2)
      self.contents.font.color = normal_color
      self.contents.font.bold = true
      self.contents.font.color = actor.hp == 0 ? knockout_color : actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color
      self.contents.draw_text(x + 143, y - 2, 150, 32, "#{actor.hp}/#{actor.maxhp}")
      self.contents.font.color = actor.sp == 0 ? crisis_color : actor.sp <= actor.maxsp / 4 ? crisis_color : normal_color
      self.contents.draw_text(x + 293, y - 2, 150, 32, "#{actor.sp}/#{actor.maxsp}")
      self.contents.font.color = system_color
      self.contents.font.size = 20
      self.contents.font.bold = false
    end
  end

  def update
    super
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      if (eval("@old_hp#{i+1}") != actor.hp or eval("@old_sp#{i+1}") != actor.sp or
        eval("@old_exp#{i+1}") != actor.now_exp)
        refresh
        eval("@old_hp#{i+1} = actor.hp; @old_sp#{i+1} = actor.sp; @old_exp#{i+1} = actor.now_exp")
      end
    end
  end
end
    
class Window_Base < Window
  def draw_slant_bar(y, x, min, max, width = 152, height = 6,
      bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255))
    for i in 0..height
      self.contents.fill_rect(x + i, y + height - i, width + 1, 1, Color.new(50, 50, 50, 255))
    end
    for i in 1..(height - 1)
      r = 100 * (height - i) / height + 0 * i / height
      g = 100 * (height - i) / height + 0 * i / height
      b = 100 * (height - i) / height + 0 * i / height
      a = 255 * (height - i) / height + 255 * i / height
      self.contents.fill_rect(x + i, y + height - i, width, 1, Color.new(r, b, g, a))
    end
    for i in 1..( (min / max.to_f) * width - 1)
      for j in 1..(height - 1)
        r = bar_color.red * (width - i) / width + end_color.red * i / width
        g = bar_color.green * (width - i) / width + end_color.green * i / width
        b = bar_color.blue * (width - i) / width + end_color.blue * i / width
        a = bar_color.alpha * (width - i) / width + end_color.alpha * i / width
        self.contents.fill_rect(x + i + j, y + height - j, 1, 1, Color.new(r, g, b, a))
      end
    end
  end
end

class Game_Actor
  def now_exp
    return @exp - @exp_list[@level]
  end
  def next_exp
    return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
  end
end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top